+ 1

Type in Command prompt

So I can open Command prompt with python code, but is there a way to have pythons code type in Command prompt ? - Thanks

5th Sep 2018, 9:35 PM
Carson
Carson - avatar
7 Réponses
6th Sep 2018, 12:23 AM
Alexander Santos
Alexander Santos - avatar
+ 1
I think understand your question, you would like to be able to open the cmdline, using Python, and have Python send commands to the cmdline? If so, "subprocess" is a preferred library: import subprocess cmd=['echo hello', 'dir'] for each in cmd: process=subprocess.Popen(each,stdout=subprocess.PIPE,shell=True) output=process.communicate()[0] print(output.decode('utf-8')) That should print out cleaner
6th Sep 2018, 3:02 AM
Steven M
Steven M - avatar
0
no, I need to open and type in command prompt automated using python.
6th Sep 2018, 12:35 AM
Carson
Carson - avatar
0
You can refer to a python file using the command above, run what you want, and then continue. The user must have Python modules though.
6th Sep 2018, 12:38 AM
Alexander Santos
Alexander Santos - avatar
0
I know, that isnt the problem, I need to type in command prompt. like if I were typing in it, but it's the code.
6th Sep 2018, 12:44 AM
Carson
Carson - avatar
0
okay, alexander's code worked, but here is my question : Is there anything else I can type into it ? - Thanks again
6th Sep 2018, 2:04 PM
Carson
Carson - avatar
0
and is there a way you can open command prompt and type in it, and open files ?
6th Sep 2018, 4:43 PM
Carson
Carson - avatar