简体   繁体   中英

python subprocess console output - eclipse calls batch calls python calls exe

I have the situation that I want the job done from eclipse so I use eclipse's .launch configuration . I tried to make it run python directly but got error: error 193 (%1 is not a valid Win32 app) . where %1 is probably my python script.

I decided to create a simple batch script that calls this big wild python animal.

I did a lot of combinations and found this the best (batch outputs some strings, runs python, waits for it, the outputs some strings again):

start /b /wait "Python_script.py" "%1" "%2" "%3" "%4" "%5"

It worked until python itself started to run exe file.

Once again I tried a lot of combinations:

os.system([exe, arg1, arg2, ...]) and subprocess.call(..) and subprocess.check_output(..)

-> I either didn't see the output in eclipse console, or the output was delayed or there was only python / or only exe's output in console.

finally I used subprocess.Popen(...) and it's nearly allright - the only defect is that the output from python script don't wait for exe's process to finish, and when I use subprocess.Popen(...).wait() exe passes output to console but the WHOLE output from python script is delayed until the 'exe' terminates . I want to delay only the part of pythons script output that is written after the exe is called.

  • how to achieve this 'partly console output delay' is the main topic
  • advices on python and eclipse .launch configuration will be appreciated
  • general advices on how does the communication between this processes(?) work will be appreciated

Thanks!

It sounds to me like you have three different processes you're trying to get to work together, you've tried a whole bunch of stuff to get it working, and the code is complex enough that you can't easily post it here. That makes it pretty hard to get a good answer (Stack Overflow works much better with focused questions), but here's the general approach I'd take:

  1. Does your script run if you try to run Python_script.py directly from the command prompt?
    • If it doesn't, then look into registering the .py file type in Windows.
    • If it does, then maybe Eclipse launch configurations don't support or don't properly support Windows registered file types. There should be no need to mess with batch files and start ; just replace Python_script.py in your launch configuration with c:\\Python27\\python.exe Python_script.py (or similar).
  2. Get your script working from a command prompt - able to run, with proper Python and subprocess output, and waiting for everything to terminate.
  3. If things work from the command prompt and still don't work from Eclipse, then post a new question with a small snippet of code showing what you're trying and a description of what's wrong. subprocess.call , subprocess.check_output , and Popen all have different uses, so it's hard to give general advice besides just referring to the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM