Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running command lines within your Python script

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?

like image 897
user2315 Avatar asked May 24 '12 16:05

user2315


People also ask

How do you run multiple lines of code in Python?

You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line. In the revised version of the script, a blank space and an underscore indicate that the statement that was started on line 1 is continued on line 2.

Can you open CMD with Python?

You just need to enter /c instead of /k this will open, run and close the command prompt. So this was how to open command prompt using python it was just one line of code you can do automation like creating project folder or installing or running program.


1 Answers

You should use the subprocess module. In particular, subprocess.call will run command line programs for you.

like image 181
murgatroid99 Avatar answered Sep 21 '22 14:09

murgatroid99