0

So I am running a command in my python py file

myNewShell = os.system('start "%s" /d "%s" cmd /f:on  /t:0A /k "W:\\Desktop\\alias.bat"' % (myShot, myWorkDir))

This opens up a shell

How exactly would I input something into this shell directly from my python script, thus bypassing your actual cmd.exe. I have a bunch of DOSKEYs set up, such as maya which opens up the maya program. How would I add a line of code to my python script, so that it loads the shell with those aliases and inputs my command directly

1
  • You are asking the same question twice. Update your original question and dont make people split the work: stackoverflow.com/questions/10741600/… Commented May 28, 2012 at 16:00

1 Answer 1

1

Take a look at the powerful and useful subprocess module

You can then do code like this

import subprocess
pro = subprocess.Popen("cmd", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
pro.stdin.write("mybat.bat\n")
pro.stdin.write("myother.bat\n")
pro.stdin.write("start mysillyprogram\n")
pro.stdin.flush()
pro.terminate() # kill the parent 
Sign up to request clarification or add additional context in comments.

1 Comment

Use the communicate() method when using PIPE, instead of accessing the fd directly... Or, dont even open a stdout here if you dont need it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.