So I have a bunch of aliases and Command Line prompt programs, and my main program works by inputting b into the cmd.exe, followed by some filepath names and what not. How would I run those arguments in my python script? So that it mimics the action i am doing in the cmd?
4 Answers
You should use the subprocess module. In particular, subprocess.call will run command line programs for you.
Comments
or you can use
import os
os.system('your_command')
for example:
import os
os.system('notepad')
will launch the notepad with the command line behind.
hope this helps
3 Comments
Jakob Bowyer
The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.
user2315
I've set up an alias so that when I type maya it opens an animation software maya. Yet when I do this, it works for notepad, but not for maya.
Infinite_Loop
I agree subprocess is way better.
You can do this using subprocess
For example, this call bellow gets the output of the program and stores it as a string, using .call will help with calling it and for more accurate control use .Popen
subprocess.check_output(["ipconfig"])
cmd.exeis this under Windows, talk of aliases made me think it was Linux/Unix.