#How to make a python script run a .bat file

14 messages · Page 1 of 1 (latest)

dreamy pier
#

I'm trying to run a windows batch file using a python script, but the batch file quickly closes after running the script

marsh ibexBOT
#

Thanks for your question :clap:, if someone gives you an answer it would be great if you thanked them with a :white_check_mark: in response. This response will earn you both points for special roles on this server.

mortal dagger
dreamy pier
#

It won't run any batch file

#

I tried with just
echo test

warped flint
#

So I tried it with this:

import os

os.system("test.bat")

And my Output what this:

>echo "This is a test!" 
"This is a test!"

This way it worked for me.

dreamy pier
#

I used os.startfile I think

#

I'll try that out

dreamy pier
#

tried os.system

#

it works fine when i run from vscode but if i run the .py itself i get this

operable program or batch file```
#

its fine if i cant get the .py to work but id prefer for it to work from there

warped flint
#

Did you enter the Absolut path? this should help to execute from anywhere

#

In my code I just executed it in the current directory so I did not need to enter the Absolut path.

dreamy pier
#

its in the same directory