0

I need to run a bat file (P:/myBat.bat) in a specific application (for example, located in C:/temp/myApp.exe). Manually I launch myApp.exe, run the code

hscript P:/myBat.bat

And I get what I need. But I wish to do it with Python.

I know how to execute a bat file with Python:

import subprocess
subprocess.Popen("P:/myBat.bat").communicate()

But how to execute hscript P:/myBat.bat via myApp.exe with Python?

1 Answer 1

1

You are looking for subprocess.call, e.g. subprocess.call(['hscript', 'P:/myBat.bat']), and its friends. See: https://docs.python.org/3/library/subprocess.html#subprocess.call

Sign up to request clarification or add additional context in comments.

8 Comments

But where should I set path to my command line application(C:/temp/myApp.exe))?
The hscript is unregistered command in Windows (from myApp.exe)
If I'm understanding you correctly, you probably want to set the working directory in which Python executes the subprocess. This is os.chdir, os.getcwd, etc.: docs.python.org/3/library/os.html#os.chdir
I have a command line application. I need to run a code (hscript P:/myBat.bat) in this application. subprocess.call(["C:/temp/myApp.exe", "hscript P:\myBat.bat" ]) runs the app but does not execute the code in this app.
It would help if you pasted the output, but you may want to try subprocess.call(["C:/temp/myApp.exe", "hscript", "P:\myBat.bat"])
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.