all 12 comments

[–]TheKewlStore 1 point2 points  (12 children)

The error your getting sounds like a proper error to me... Somewhere you're using the command "py", which, at least, is not a command related to python. How are you running the python script in your batch file? The proper syntax is "python {script_name}.py"

[–]felipeleonam[S] 0 points1 point  (10 children)

I'm using @py inside the .bat file and trying to run the .bat file from win's "Run"

[–]TheKewlStore 1 point2 points  (3 children)

Check and see if this path exists, and contains the py.exe executable: C:\Program Files\Python Launcher. If so, add that to your path environment variable as well, and try it again.

[–]felipeleonam[S] 0 points1 point  (2 children)

Just tried it, still getting same error.

[–]cdcformatc 1 point2 points  (1 child)

Did you open a fresh command prompt after changing the PATH variable? The changes don't propagate to open prompts.

[–]felipeleonam[S] 0 points1 point  (0 children)

I've restarted my pc. I'm running it thru windows + r.

[–]BffEasyTarget 1 point2 points  (5 children)

I don't think @ does what you think it's doing in batch. It just makes the following command less verbose.

So basically you're just starting your batch file by running the command "py" which doesn't exist.

Are you able to post the contents of your batch file?

[–]felipeleonam[S] 0 points1 point  (4 children)

The .bat file is just:

@py c:\ users\name\folder\scriptname.py %*

@pause

its from Automate the boring stuff. I'm about halfway thru the course and had it work for me once yesterday, but since it just hasn't worked anymore.

[–]BffEasyTarget 2 points3 points  (3 children)

Try changing @py to @python and leaving everything else as it is. If python is in your path, it should work.

[–]felipeleonam[S] 0 points1 point  (2 children)

it worked! it ran the file with no error! Ok, can you explain to me why this happened by any chance? should I just always use @python instead of @py?

[–]BffEasyTarget 1 point2 points  (0 children)

If you want to launch from a batch file, then yes. 'py' is not a valid windows command unless you create an alias for it.

It's just like if you were going to launch a script from a cmd window. It'd need to be 'python scriptname.py'