1.

Solve : Batch to run a python file?

Answer»

Hi,

I need some help constructing some code for a batchfile. The .bat should run a file called "worker.py" USING the python command "python" infront of it. Anyone know how to do this?

( it's a pain in the *censored* writing "cd c:\rendertester\" to navigate and then write "python worker.py 192.173.5.6:8080" all the time in the cmd )

so your TRYING to open a file with a batch right?

@ ECHO off
echo This will open a file
start (put the file location like C:/dir/dir/dir)
Quote from: KaizerKaizer on March 10, 2009, 05:30:46 PM

it's a pain in the *censored* writing "cd c:\rendertester\" to navigate and then write "python worker.py 192.173.5.6:8080" all the time in the cmd

Code: [Select]@echo off
cd c:\rendertester
python worker.py 192.173.5.6:8080
Nope already tried that. that only starts python.exe and not the file. If I do it manually there is no problem.
Quote from: KaizerKaizer on March 11, 2009, 02:10:47 AM
Nope already tried that. that only starts python.exe and not the file. If I do it manually there is no problem.


Try with full paths for both Python executable and script, using quotes if there are any spaces.

google.py is an example script included in the Python 2.6.1 download from python.org. It takes a search term as a PARAMETER and runs it on Google in the system default browser.

This works for me in a batch file (in the folder where google.py lives)...

Code: [Select]"c:\Program Files\Python\python.exe" google.py Britney Spears
...and this works anywhere on my system...

Code: [Select]"c:\Program Files\Python\python.exe" "C:\Program Files\Python\Tools\Scripts\google.py" Britney Spears
Your paths may be different...
well, that worked better...but still not as it should.

It works as long as I don't add the "http://192.ip-address" in the end.

I use python 2.5 with twisted
how is worker.py importing the command line argument?


Discussion

No Comment Found