Home > other >  Python call an external application and return immediately
Python call an external application and return immediately

Time:11-17

I call an external application in python, I found not make, my goal is to call the external program let it run alone there, and a host program is completely independent of two programs, but I test, but not what I want effect,
In order to facilitate the narrative below, python program called p, called program called c program, called with a parameter, as follows:
The path of the exePath: c program
ParString: argument string

I tested a few ways, the result is as follows:
OS. Execv (exePath parString), p program will be shut down, c program can start, but can't get the right parameter
Ditto for your OS. Execl (exePath parString)
OS. Execle (exePath parString), c program is not running, p program crashes
OS. Execlp (exePath parString), p program will be shut down, c program can start, but can't get the right parameter
Ditto for your OS. Execvp (exePath parString)
OS. Execlpe (exePath parString), c program is not running, p program crashes
OS. Startfile (exePath + "" + parString), ditto
OS. The system (exePath + "" + parString), c programs can run normally, but before the end of the c program, p
no response
From the test results, the most close to the target is the last one, OS, system (), but before the end of the c program, p application could not continue to run, it is very good,
Do not know to have what interface can achieve my goal, in other words, there is no such interface?

CodePudding user response:

Can try solve with multithreading, open a new thread to invoke the OS. The system (XXXX), don't directly in the main thread to execute the OS. The system
So give it a try and see can solve the problem of p application no response

CodePudding user response:

reference procedures for building a smile monkey response:
try solve with multithreading, open a new thread to invoke the OS. The system (XXXX), don't directly in the main thread to execute the OS. The system
So give it a try and see can solve the problem of no response p program

So there should be no problem, just want to a small function, don't want to bother, but if you use a thread, the closed p program before the end of the c program, the c program estimates will be forced to shut down

CodePudding user response:

Just saw your post, has been in the past few months, estimates the building has been resolved, in order to make the post is complete, I answer:
OS. The system (exePath + "" + parString), c programs can run normally, but before the end of the c program, p
no responseMain program p is the cause of no response, OS, system () need DengZi program c is completed, will not return to the main program p;

So I need to use another subprocess. Popen () methods:
The import subprocess
Subprocess. Popen (exePath + "" + parString) c programs can run normally, and p program may continue to
# print (" confirmed return p main program ") # debug statements

CodePudding user response:

reference xuxu6328 reply: 3/f
just saw your post, has been in the past few months, estimates that the building has been resolved, in order to make the post is complete, I answer:
OS. The system (exePath + "" + parString), c programs can run normally, but before the end of the c program, p
no responseMain program p is the cause of no response, OS, system () need DengZi program c is completed, will not return to the main program p;

So I need to use another subprocess. Popen () methods:
The import subprocess
Subprocess. Popen (exePath + "" + parString) c programs can run normally, and p program may continue to
# print (" confirmed return p main program ") # debug statements

Starts when I try to say again,
This problem has been solved, this goal is not required, because I just want to get more tools to unite with, make the whole work process more convenient, so has been didn't do more research for it

CodePudding user response:

I also met the same problem, use the following can be solved.
# a non-blocking call
# filename for the file path string
The from subprocess import Popen

The process=Popen (args=filename, shell=True)
Next:fadsfas
  • Related