如何用命令运行程序?

时间:2011-03-01 18:38:31

标签: c# windows-mobile windows-ce

我需要在Windows-CE或Windows-Mobile中使用命令运行程序

例如:RunMe.exe trueRunMe.exe false

如果程序返回true,程序将执行某些操作,如果程序返回false

该计划将采取其他措施。

我该如何做到这一点?

3 个答案:

答案 0 :(得分:1)

你的问题不清楚。

如果您要编写此类程序,请使用string[] args参数Main()
(或致电Environment.GetCommandLineArguments()

如果您想运行此类程序,请致电Process.Start

答案 1 :(得分:0)

来自this question(来自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 = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

答案 2 :(得分:0)

如果要在不编写其他程序的情况下执行此操作,可以创建快捷方式文件以使用所需的命令行选项启动应用程序。

快捷方式文件的格式如下所示:

[number of ASCII characters after pound sign allocated to command-line arguments]#[command line] [optional parameters]

例如:

40#\Windows\MyApp.exe parameter1 parameter2

请参阅:http://msdn.microsoft.com/en-us/library/ms861519.aspx

相关问题