问题描述
我有一个从客户端接收命令并运行它们的服务器。
这些命令使用一个特定的批处理脚本,它接收参数和运行。
该脚本调用这些参数外部的控制台应用程序。
这些参数还可以指示脚本运行控制台应用程序的多个实例,在后台运行。因此,其结果可能是一个打开的 CMD
,运行 APP.EXE
3的情况下,在后台运行。
I have a server which receives commands from a client and runs them.These commands use one specific batch script, which receives arguments and runs.The script calls an external console application program with these arguments.The arguments can also instruct the script to run multiple instances of the console application, in the background. So, the outcome could be one open CMD
, running 3 instances of app.exe
, in the background.
我想知道什么时候结束的 APP.EXE
这些流程中的每一个(并获得其参数每个人的具体命令行),并发送到客户端
I wish to know when each one of those processes of app.exe
finish (and get each one's specific command line with its arguments), and send that to the client.
任何想法?
推荐答案
你有没有想过从backgound工人调用此脚本?
have you thought about calling this script from a backgound worker?
您backgoundworker将执行这样的:
You backgoundworker would execute something like this:
static void ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
process.Close();
}
static void Main()
{
ExecuteCommand("echo testing");
}
这样,如果这个过程是通过检查BackgroundWorker.IsBusy状态做,你可以测试一下。有史以来过程完成时,您甚至可以更新用户。
This way you can test if the process is done by checking the BackgroundWorker.IsBusy state. You can even update the user when ever the process finishes.
希望这有助于!
这篇关于找出如果一个进程运行完毕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!