Python Popen, OS, Commands all return nothing when running a command in linux










0














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









share|improve this question





















  • 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
















0














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









share|improve this question





















  • 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














0












0








0







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









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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













3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer




















  • 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


















0














This will only work on *nix:



import commands
print commands.getstatusoutput('javac -version')





share|improve this answer




















  • 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


















0














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






share|improve this answer




















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer




















    • 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















    1














    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.






    share|improve this answer




















    • 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













    1












    1








    1






    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.






    share|improve this answer












    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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
















    • 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













    0














    This will only work on *nix:



    import commands
    print commands.getstatusoutput('javac -version')





    share|improve this answer




















    • 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















    0














    This will only work on *nix:



    import commands
    print commands.getstatusoutput('javac -version')





    share|improve this answer




















    • 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













    0












    0








    0






    This will only work on *nix:



    import commands
    print commands.getstatusoutput('javac -version')





    share|improve this answer












    This will only work on *nix:



    import commands
    print commands.getstatusoutput('javac -version')






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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
















    • 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











    0














    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






    share|improve this answer

























      0














      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






      share|improve this answer























        0












        0








        0






        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 17:37









        SomeSimpletonSomeSimpleton

        84




        84



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto