Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output going to stderr #15

Open
anne-jones opened this issue Apr 23, 2019 · 3 comments
Open

Output going to stderr #15

anne-jones opened this issue Apr 23, 2019 · 3 comments

Comments

@anne-jones
Copy link

I'm doing a purge invalidate command in a python script using subprocess and getting the results with communicate().

The issue is that the output is being sent to stderr and I'm not sure the best way to tell when the purge has succeeded or failed. I found this comment on an akamai forum where another user was having the same problem, but it's been almost a year and no one ever answered.

Can anyone help with this? Thanks!

@dshafik
Copy link
Contributor

dshafik commented Apr 23, 2019

@anne-jones there are two ways to determine if the purge was successful:

Hopefully this helps?

@anne-jones
Copy link
Author

Thanks so much for your response!

  • I have a check on the returncode and I log an error if it's non-zero, but I didn't see that happen when the purge "failed," though I may have figured out why that is. When I ran the purge command from the command line it asked me if I wanted to update (y/n) which isn't something my script handles. Though I find it strange that nothing printed out if that's why the purge didn't work (see code below to see what I mean).

  • Here is example code of what I've been doing:

command = CONFIG_DATA["akamai_cli"] + " purge --edgerc " + CONFIG_DATA["edgerc"] + " invalidate --cpcode " + cpcode()
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
# akamai prints to error ?_? instead of output
print("Error: " + error.decode('UTF-8'))
print("Output:" + output.decode('UTF-8'))
if (process.returncode):
   raise Exception("Error running akamai purge")

Here are the results of running the code:
image

As you can see the results are coming through the stderr pipe and I'm not getting anything through stdout.

@dshafik
Copy link
Contributor

dshafik commented Jul 18, 2019

@anne-jones this is the correct behavior — the CLI — like many other tools — only outputs data that is meant to be piped to other applications to STDOUT, and we use STDERR for all other (e.g. informational) output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants