mardi 28 juin 2016

difference in program behavior when run from python script and from windows

Some background:
A program runs a manufacturing machine. This program runs on windows XP. The program controls the machine and writes a simple manufacturing log.
I wrote a python script that asks the user to enter current manufacturing project name. the script writes project name to log file. This way, I have "project deviders" in the log file, and i can know which ,manufacturing data belongs to which project.
The script works fine: project names are written to log file if not exist there before, and machine program executes.
Problem is, that the program does not write manufacturing data to log file when run from script. Only when run from windows.
I tried running two instances of the program: one from windows and one from script. Script writes project name to file successfuly, and windows run program writes data to file successfuly. So i think it's not a problem of the log file locked by the script. I also checked that both programs run under same user, so it's not a credentials problem.
Here's the script:

file = open("C:\Documents and Settings\User1\Desktop\BPanelBadePanel\SteelUsage.bsu", "a+")
input = raw_input("Please enter project name:")
input = input.upper ()
for line in file.readlines():
        if input in line:
            print "Project name already exists, executing BadePanel"
            import time
            time.sleep(4)
            import subprocess
            subprocess.Popen(['C:\Documents and Settings\User1\Desktop\BPanelBadePanel\BadePanel.exe'])
            sys.exit(0)
file.write (input+"n")
print "Project name written to file, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.Popen(['C:\Documents and Settings\User1\Desktop\BPanelBadePanel\BadePanel.exe'])
sys.exit(0)
file.close()  

I also tried using import os with os.system, and import suprocess with subprocess.call, instead of subprocess.Popen
Both gave same result.
Thank you

Aucun commentaire:

Enregistrer un commentaire