Execute Commands Sequentially in Python?

前端 未结 5 1933
猫巷女王i
猫巷女王i 2020-12-03 07:33

I would like to execute multiple commands in a row:

i.e. (just to illustrate my need):

cmd (the shell)

then

cd dir<

5条回答
  •  无人及你
    2020-12-03 08:05

    below python script have 3 function what you went just excute:

    import sys
    import subprocess
    
    def cd(self,line):
        proc1 = subprocess.Popen(['cd'],stdin=subprocess.PIPE)
        proc1.communicate()
    
    def ls(self,line):
        proc2 = subprocess.Popen(['ls','-l'],stdin=subprocess.PIPE)
        proc2.communicate()
    
    def dir(silf,line):
        proc3 = subprocess.Popen(['cd',args],stdin=subprocess.PIPE)
        proc3.communicate(sys.argv[1])
    

提交回复
热议问题