How to read a command than press enter automatically? [closed]











up vote
-2
down vote

favorite












In normal case, in order to stop my programm from running I put in command line 'quit' than I press Enter Key.
However I need to make that from a python file.



os.system("echo  'quitn' ")


I use this instruction but my program keep working. It does not stop.










share|improve this question













closed as unclear what you're asking by OrangeDog, MisterMiyagi, Socowi, gnat, Goyo Nov 27 at 14:33


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Do you want to quit the program to exit at a certain point? Then just use sys.exit().
    – Ben T.
    Nov 22 at 12:39






  • 1




    Are you referring to another program (which you did not write) where you want to have your script type in quit?
    – usr2564301
    Nov 22 at 12:40










  • @MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
    – Sony
    Nov 22 at 12:52










  • @usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
    – Sony
    Nov 22 at 13:01










  • @Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
    – MisterMiyagi
    Nov 22 at 13:15















up vote
-2
down vote

favorite












In normal case, in order to stop my programm from running I put in command line 'quit' than I press Enter Key.
However I need to make that from a python file.



os.system("echo  'quitn' ")


I use this instruction but my program keep working. It does not stop.










share|improve this question













closed as unclear what you're asking by OrangeDog, MisterMiyagi, Socowi, gnat, Goyo Nov 27 at 14:33


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Do you want to quit the program to exit at a certain point? Then just use sys.exit().
    – Ben T.
    Nov 22 at 12:39






  • 1




    Are you referring to another program (which you did not write) where you want to have your script type in quit?
    – usr2564301
    Nov 22 at 12:40










  • @MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
    – Sony
    Nov 22 at 12:52










  • @usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
    – Sony
    Nov 22 at 13:01










  • @Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
    – MisterMiyagi
    Nov 22 at 13:15













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











In normal case, in order to stop my programm from running I put in command line 'quit' than I press Enter Key.
However I need to make that from a python file.



os.system("echo  'quitn' ")


I use this instruction but my program keep working. It does not stop.










share|improve this question













In normal case, in order to stop my programm from running I put in command line 'quit' than I press Enter Key.
However I need to make that from a python file.



os.system("echo  'quitn' ")


I use this instruction but my program keep working. It does not stop.







python bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 12:35









Sony

668




668




closed as unclear what you're asking by OrangeDog, MisterMiyagi, Socowi, gnat, Goyo Nov 27 at 14:33


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by OrangeDog, MisterMiyagi, Socowi, gnat, Goyo Nov 27 at 14:33


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Do you want to quit the program to exit at a certain point? Then just use sys.exit().
    – Ben T.
    Nov 22 at 12:39






  • 1




    Are you referring to another program (which you did not write) where you want to have your script type in quit?
    – usr2564301
    Nov 22 at 12:40










  • @MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
    – Sony
    Nov 22 at 12:52










  • @usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
    – Sony
    Nov 22 at 13:01










  • @Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
    – MisterMiyagi
    Nov 22 at 13:15


















  • Do you want to quit the program to exit at a certain point? Then just use sys.exit().
    – Ben T.
    Nov 22 at 12:39






  • 1




    Are you referring to another program (which you did not write) where you want to have your script type in quit?
    – usr2564301
    Nov 22 at 12:40










  • @MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
    – Sony
    Nov 22 at 12:52










  • @usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
    – Sony
    Nov 22 at 13:01










  • @Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
    – MisterMiyagi
    Nov 22 at 13:15
















Do you want to quit the program to exit at a certain point? Then just use sys.exit().
– Ben T.
Nov 22 at 12:39




Do you want to quit the program to exit at a certain point? Then just use sys.exit().
– Ben T.
Nov 22 at 12:39




1




1




Are you referring to another program (which you did not write) where you want to have your script type in quit?
– usr2564301
Nov 22 at 12:40




Are you referring to another program (which you did not write) where you want to have your script type in quit?
– usr2564301
Nov 22 at 12:40












@MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
– Sony
Nov 22 at 12:52




@MisterMiyagi it is another program , I use python to launch its execution. I put quit to stop it
– Sony
Nov 22 at 12:52












@usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
– Sony
Nov 22 at 13:01




@usr2564301 yes I need to type 'quit' in my script to running another program that In don't write in my question.
– Sony
Nov 22 at 13:01












@Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
– MisterMiyagi
Nov 22 at 13:15




@Sony How did you start it from Python? os.system, subprocess.run, subprocess.Popen, ...
– MisterMiyagi
Nov 22 at 13:15












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Spawn your child programs using subprocess.Popen. This gives you a wrapper object that serves as a handle to the child.



import subprocess

child = subprocess.Popen(["sleep", "10"], stdin=subprocess.PIPE)
print(child.poll()) # current status of the child - None if still running
# write to the child's stdin
child.stdin.write(b'quitn')
print(child.wait()) # wait until child has shut down


By using Popen(..., stdin=subprocess.PIPE) you create a standing connection the the child's stdin. This can be used for writing via child.stdin.






share|improve this answer




























    up vote
    0
    down vote













    You don't actually send your "quit n" command to the standard input of the program you want to stop, but for the standard output of your python script.
    I am not sure how do you run this program you mentioned but you may read about using pipes to redirect outputs from one app to inputs of another.






    share|improve this answer





















    • I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
      – Sony
      Nov 22 at 12:54


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Spawn your child programs using subprocess.Popen. This gives you a wrapper object that serves as a handle to the child.



    import subprocess

    child = subprocess.Popen(["sleep", "10"], stdin=subprocess.PIPE)
    print(child.poll()) # current status of the child - None if still running
    # write to the child's stdin
    child.stdin.write(b'quitn')
    print(child.wait()) # wait until child has shut down


    By using Popen(..., stdin=subprocess.PIPE) you create a standing connection the the child's stdin. This can be used for writing via child.stdin.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      Spawn your child programs using subprocess.Popen. This gives you a wrapper object that serves as a handle to the child.



      import subprocess

      child = subprocess.Popen(["sleep", "10"], stdin=subprocess.PIPE)
      print(child.poll()) # current status of the child - None if still running
      # write to the child's stdin
      child.stdin.write(b'quitn')
      print(child.wait()) # wait until child has shut down


      By using Popen(..., stdin=subprocess.PIPE) you create a standing connection the the child's stdin. This can be used for writing via child.stdin.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Spawn your child programs using subprocess.Popen. This gives you a wrapper object that serves as a handle to the child.



        import subprocess

        child = subprocess.Popen(["sleep", "10"], stdin=subprocess.PIPE)
        print(child.poll()) # current status of the child - None if still running
        # write to the child's stdin
        child.stdin.write(b'quitn')
        print(child.wait()) # wait until child has shut down


        By using Popen(..., stdin=subprocess.PIPE) you create a standing connection the the child's stdin. This can be used for writing via child.stdin.






        share|improve this answer












        Spawn your child programs using subprocess.Popen. This gives you a wrapper object that serves as a handle to the child.



        import subprocess

        child = subprocess.Popen(["sleep", "10"], stdin=subprocess.PIPE)
        print(child.poll()) # current status of the child - None if still running
        # write to the child's stdin
        child.stdin.write(b'quitn')
        print(child.wait()) # wait until child has shut down


        By using Popen(..., stdin=subprocess.PIPE) you create a standing connection the the child's stdin. This can be used for writing via child.stdin.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 13:26









        MisterMiyagi

        7,2652040




        7,2652040
























            up vote
            0
            down vote













            You don't actually send your "quit n" command to the standard input of the program you want to stop, but for the standard output of your python script.
            I am not sure how do you run this program you mentioned but you may read about using pipes to redirect outputs from one app to inputs of another.






            share|improve this answer





















            • I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
              – Sony
              Nov 22 at 12:54















            up vote
            0
            down vote













            You don't actually send your "quit n" command to the standard input of the program you want to stop, but for the standard output of your python script.
            I am not sure how do you run this program you mentioned but you may read about using pipes to redirect outputs from one app to inputs of another.






            share|improve this answer





















            • I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
              – Sony
              Nov 22 at 12:54













            up vote
            0
            down vote










            up vote
            0
            down vote









            You don't actually send your "quit n" command to the standard input of the program you want to stop, but for the standard output of your python script.
            I am not sure how do you run this program you mentioned but you may read about using pipes to redirect outputs from one app to inputs of another.






            share|improve this answer












            You don't actually send your "quit n" command to the standard input of the program you want to stop, but for the standard output of your python script.
            I am not sure how do you run this program you mentioned but you may read about using pipes to redirect outputs from one app to inputs of another.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 12:40









            running.t

            2,44311338




            2,44311338












            • I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
              – Sony
              Nov 22 at 12:54


















            • I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
              – Sony
              Nov 22 at 12:54
















            I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
            – Sony
            Nov 22 at 12:54




            I run my program by this way os.system("./toto"), after period of time I stop its running by using os.system("echo 'quitn' ") however this instruction doesn't work
            – Sony
            Nov 22 at 12:54



            Popular posts from this blog

            Futebolista

            Lallio

            Jornalista