Trying to execute batch file from Python

This is the place for queries that don't fit in any of the other categories.

Trying to execute batch file from Python

Postby QuantumTarantino » Wed Sep 28, 2016 9:32 pm

I have a batch file and a corresponding text file on another drive (not C: or D:). When I drag the txt file onto the batch file it sees the file as input and processes the text file.

The issue is that I was trying to use subprocess.popen to run the batch with the text file as input. The key thing to understand here is that the batch file calls a perl script with the notation
"- perl"

When I drag and drop the text onto the batch manually, there are no issues. When I try to use popen, I get a "perl is not recognized as internal or external command or program". The weird part is, popen works on my local D drive. But not on the "Q" drive. Except dragging the text file onto the batch (both are in the Q drive) works fine.

So what's happening here. Drag and drop manually works and popen (even with passing the filename as argument to the batch) doesn't work? Except for on my local D drive?

I am providing both the full path of the batch and filename by the way for popen.

file1 = [path]\\test.bat
file2 = [path]\\filename.txt

Note [Path] is a path on another drive. Both files are in the same directory.

p.subprocess.popen([file1,file2])
#Doesn't work. Gives me perl is not recognized program or command

Drag and Drop into batch #WORKS.
QuantumTarantino
 
Posts: 3
Joined: Tue Aug 02, 2016 4:42 am

Re: Trying to execute batch file from Python

Postby Ofnuts » Fri Sep 30, 2016 11:46 am

When you drag things, the current drive and directory are set to the drive/directory of the object. If your Perl executable is not in the PATH, or if its path is not fully specified, then finding it is subject to current drive and directory.
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests