Reputation: 5514
I have a Python script which needs to be run with a batch file, but I've been using cmd to test it. When run through cmd, it works fine. However, the script seems to behave differently when run through the batch file. I've isolated the section of code which seems to be the problem:
CRFOLDER = "some path to all my files"
isReady = False
os.startfile(os.path.join(CRFOLDER,"CLogger.exe"))
while not isReady:
try:
open(os.path.join(CRFOLDER,"CRPYLog.py"))
isReady = True
except:
print "Not ready yet"
time.sleep(0.25)
import CRPYLog as PyLog
This code calls an executable which creates a Python file, which I then import (if you're curious about the reason, check here). As I said, this works fine when run through cmd. However, when I use the batch file, the while
loop runs infinitely (or at least for 2 minutes, when run through cmd it hits the except
just once). This is weird. I checked this, this, and this question with no luck. The batch file is below.
start Y:\Admin\Anaconda\python.exe "Y:\Projects\Advent - Overhead Projects\Copy - ADV001 - CR Records Management - Copy\Python\CRWizard.py"
I've tried pasting that exact command into cmd and it worked fine, but the batch file does not. Thanks in advance
Upvotes: 4
Views: 2075
Reputation: 14360
You don't have to type the start command for that. See this. Just remove the start command.
Y:\Admin\Anaconda\python.exe "Y:\Projects\Advent - Overhead Projects\Copy - ADV001 - CR Records Management - Copy\Python\CRWizard.py"
Upvotes: 0
Reputation: 451
Probably, your batch file is running excutable with windows native call (os.startfile
), and hence sets some defaults (current folder), forcing executable to create resulting file in folder that differs from expected CRFOLDER
.
I suggest you to specify excplicetely in which foder you need this .py
file to be created, for example, to be a flexible solution, as a paramether to executable.
Upvotes: 2