How to detect if a process is running using Python on Win and MAC

psutil is a cross-platform library that retrieves information about running processes and system utilization. import psutil pythons_psutil = [] for p in psutil.process_iter(): try: if p.name() == ‘python.exe’: pythons_psutil.append(p) except psutil.Error: pass >>> pythons_psutil [<psutil.Process(pid=16988, name=”python.exe”) at 25793424>] >>> print(*sorted(pythons_psutil[0].as_dict()), sep=’\n’) cmdline connections cpu_affinity cpu_percent cpu_times create_time cwd exe io_counters ionice memory_info memory_info_ex memory_maps memory_percent … Read more

How to kill a process without getting a “process has exited” exception?

You could P/Invoke TerminateProcess passing it Process.Handle. Then manually evaluating the cause of it (GetLastError()). Which is roughly, what Process.Kill() does internally. But note that TerminateProcess is asynchronous. So you’d have to wait on the process handle to be sure it is done. Using Process.Kill() does that for your. Update: Correction, Process.Kill() also runs asynchronously. … Read more

Process started by Process.start() returns incorrect process ID?

An example of how I did it: bool started = false; var p = new Process(); p.StartInfo.FileName = “notepad.exe”; started = p.Start(); try { var procId = p.Id; Console.WriteLine(“ID: ” + procId); } catch(InvalidOperationException) { started = false; } catch(Exception ex) { started = false; } Otherwise, try using handles like this: Using handlers Getting … Read more

php in background exec() function

exec() will block until the process you’re exec’ing has completed – in otherwords, you’re basically running your ‘test.php’ as a subroutine. At bare minimum you need to add a & to the command line arguments, which would put that exec()’d process into the background: exec(“php test.php {$test[‘id’]} &”);

Redirect process output C#

Use RedirectStandardOutput. Sample from MSDN: // Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = “Write500Lines.exe”; p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // … Read more

Visual Basic Capture output of cmd

More than one problem. First off, as @shf301 already told you, you forgot to read stderr. He in turn forgot to add an extra line: Process.Start() AddHandler Process.OutputDataReceived, _ Sub(processSender As Object, lineOut As DataReceivedEventArgs) output += lineOut.Data + vbCrLf End Sub Process.BeginOutputReadLine() AddHandler Process.ErrorDataReceived, _ Sub(processSender As Object, lineOut As DataReceivedEventArgs) output += lineOut.Data … Read more

Just check status process in c

Then you want to use the waitpid function with the WNOHANG option: #include <sys/types.h> #include <sys/wait.h> int status; pid_t return_pid = waitpid(process_id, &status, WNOHANG); /* WNOHANG def’d in wait.h */ if (return_pid == -1) { /* error */ } else if (return_pid == 0) { /* child is still running */ } else if (return_pid … Read more