2

I'm looking to be able to send commands to the CMD (windows). I need to be able to send multiple commands and have them run on the CMD.

The specific commands I need to send are:

  1. cd "C:\Python27\Scripts"
  2. pyinstaller.exe --clean --win-private-assemblies -F --onefile –windowed --icon=app.ico app.py

Is this easily possible?

4
  • 1
    yes. use the subprocess module Commented Dec 9, 2016 at 17:10
  • you can use a library that makes you able to send key to cmd or other Commented Dec 9, 2016 at 17:14
  • If you know the commands in advance, you can create a batch file and execute it as shown in my answer to a related question. Commented Dec 9, 2016 at 17:31
  • You don't need cmd.exe. Just use subprocess for this, e.g. subprocess.check_call([r'C:\Python27\Scripts\pyinstaller.exe', '--clean', '--win-private-assemblies', '-F', '--onefile', '--windowed', '--icon=app.ico', 'app.py'], cwd=r'C:\Python27\Scripts'). Passing the cwd option is necessary if that's where "app.ico" and "app.py" are located. Commented Dec 9, 2016 at 19:13

1 Answer 1

1

Very simple, you can either user the subprocess module for each command, or you can write all the commands to a bat file and execute that.

import os
script = '''
cd "C:\Python27\Scripts" 
pyinstaller.exe --clean --win-private-assemblies -F --onefile –windowed --icon=app.ico app.py
'''

with open('tmpscript.bat') as file_: 
    file_.write(script)
# either system or subprocess will work here
os.system('tmpscript.bat')
Sign up to request clarification or add additional context in comments.

Comments

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.