Python Popen, OS, Commands all return nothing when running a command in linux
So I need to get the version of something on a client and when I try to use Popen, Call, Check_Call, OS, Commands it all returns a value of nothing. When I run the script on a system in putty it returns me an empty line. Can it be because of putty?. Running on Linux, CentOS if that makes any difference. Thank you guys ahead of time.
def getJavacVer():
p = sp.Popen("javac -version", stdout=sp.PIPE, shell=True)
(output, err) = p.communicate()
print output
python python-2.7 subprocess
add a comment |
So I need to get the version of something on a client and when I try to use Popen, Call, Check_Call, OS, Commands it all returns a value of nothing. When I run the script on a system in putty it returns me an empty line. Can it be because of putty?. Running on Linux, CentOS if that makes any difference. Thank you guys ahead of time.
def getJavacVer():
p = sp.Popen("javac -version", stdout=sp.PIPE, shell=True)
(output, err) = p.communicate()
print output
python python-2.7 subprocess
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30
add a comment |
So I need to get the version of something on a client and when I try to use Popen, Call, Check_Call, OS, Commands it all returns a value of nothing. When I run the script on a system in putty it returns me an empty line. Can it be because of putty?. Running on Linux, CentOS if that makes any difference. Thank you guys ahead of time.
def getJavacVer():
p = sp.Popen("javac -version", stdout=sp.PIPE, shell=True)
(output, err) = p.communicate()
print output
python python-2.7 subprocess
So I need to get the version of something on a client and when I try to use Popen, Call, Check_Call, OS, Commands it all returns a value of nothing. When I run the script on a system in putty it returns me an empty line. Can it be because of putty?. Running on Linux, CentOS if that makes any difference. Thank you guys ahead of time.
def getJavacVer():
p = sp.Popen("javac -version", stdout=sp.PIPE, shell=True)
(output, err) = p.communicate()
print output
python python-2.7 subprocess
python python-2.7 subprocess
asked Nov 13 '18 at 1:19
SomeSimpletonSomeSimpleton
84
84
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30
add a comment |
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30
add a comment |
3 Answers
3
active
oldest
votes
The javac
program returns the -version
output through stderr
, so stderr
argument of Popen
also need to be passed. Try:
>>> from subprocess import Popen
>>> from subprocess import PIPE
>>> p = Popen(['javac', '-version'], stdout=PIPE, stderr=PIPE)
>>> p.communicate()
(b'', b'javac 1.8.0_171n')
The second element is of the result is the captured output of the stderr
stream, which contains the version number.
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
add a comment |
This will only work on *nix:
import commands
print commands.getstatusoutput('javac -version')
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
add a comment |
Thank you to the few fellas that answered the question. The output is being put out to stderr instead of stdout. Thank you to everyone
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272401%2fpython-popen-os-commands-all-return-nothing-when-running-a-command-in-linux%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The javac
program returns the -version
output through stderr
, so stderr
argument of Popen
also need to be passed. Try:
>>> from subprocess import Popen
>>> from subprocess import PIPE
>>> p = Popen(['javac', '-version'], stdout=PIPE, stderr=PIPE)
>>> p.communicate()
(b'', b'javac 1.8.0_171n')
The second element is of the result is the captured output of the stderr
stream, which contains the version number.
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
add a comment |
The javac
program returns the -version
output through stderr
, so stderr
argument of Popen
also need to be passed. Try:
>>> from subprocess import Popen
>>> from subprocess import PIPE
>>> p = Popen(['javac', '-version'], stdout=PIPE, stderr=PIPE)
>>> p.communicate()
(b'', b'javac 1.8.0_171n')
The second element is of the result is the captured output of the stderr
stream, which contains the version number.
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
add a comment |
The javac
program returns the -version
output through stderr
, so stderr
argument of Popen
also need to be passed. Try:
>>> from subprocess import Popen
>>> from subprocess import PIPE
>>> p = Popen(['javac', '-version'], stdout=PIPE, stderr=PIPE)
>>> p.communicate()
(b'', b'javac 1.8.0_171n')
The second element is of the result is the captured output of the stderr
stream, which contains the version number.
The javac
program returns the -version
output through stderr
, so stderr
argument of Popen
also need to be passed. Try:
>>> from subprocess import Popen
>>> from subprocess import PIPE
>>> p = Popen(['javac', '-version'], stdout=PIPE, stderr=PIPE)
>>> p.communicate()
(b'', b'javac 1.8.0_171n')
The second element is of the result is the captured output of the stderr
stream, which contains the version number.
answered Nov 13 '18 at 1:32
metatoastermetatoaster
9,76212640
9,76212640
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
add a comment |
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
Wow okay, this is very interesting. Thank you for awnsering my question. I have a secondary question is there any reason for it returning it to stderr?
– SomeSimpleton
Nov 13 '18 at 1:36
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
The developers behind it might think that those particular output don't belong to the standard stream - however, these kind of decisions are up to whoever that wrote the program so you will have to ask them.
– metatoaster
Nov 13 '18 at 1:47
add a comment |
This will only work on *nix:
import commands
print commands.getstatusoutput('javac -version')
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
add a comment |
This will only work on *nix:
import commands
print commands.getstatusoutput('javac -version')
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
add a comment |
This will only work on *nix:
import commands
print commands.getstatusoutput('javac -version')
This will only work on *nix:
import commands
print commands.getstatusoutput('javac -version')
answered Nov 13 '18 at 1:22
Madison CourtoMadison Courto
424212
424212
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
add a comment |
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Okay this one worked. Thank you
– SomeSimpleton
Nov 13 '18 at 1:34
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
Would you mind marking as answered please
– Madison Courto
Dec 24 '18 at 17:41
add a comment |
Thank you to the few fellas that answered the question. The output is being put out to stderr instead of stdout. Thank you to everyone
add a comment |
Thank you to the few fellas that answered the question. The output is being put out to stderr instead of stdout. Thank you to everyone
add a comment |
Thank you to the few fellas that answered the question. The output is being put out to stderr instead of stdout. Thank you to everyone
Thank you to the few fellas that answered the question. The output is being put out to stderr instead of stdout. Thank you to everyone
answered Nov 13 '18 at 17:37
SomeSimpletonSomeSimpleton
84
84
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272401%2fpython-popen-os-commands-all-return-nothing-when-running-a-command-in-linux%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible solution might be giving complete path for "javac". Also, PIPE stderr as well and check it. You might find something there
– Shriroop Joshi
Nov 13 '18 at 1:30