简体   繁体   English

如何用命令运行程序?

[英]how to run program with command?

i need to run program with command in Windows-CE or Windows-Mobile 我需要在Windows-CE或Windows-Mobile中使用命令运行程序

for example: RunMe.exe true or RunMe.exe false 例如: RunMe.exe trueRunMe.exe false

if the program returns true the program will do something and if the program returns false 如果程序返回true,则程序将执行某些操作,并且如果程序返回false

the program will do something else. 该程序将执行其他操作。

how can I accomplish this ? 我该怎么做呢?

Your question is unclear. 您的问题不清楚。

If you want to write such a program, use the string[] args parameter to Main() . 如果要编写这样的程序,请对Main()使用string[] args参数。
(Or call Environment.GetCommandLineArguments() ) (或调用Environment.GetCommandLineArguments()

If you want to run such a program, call Process.Start . 如果要运行这样的程序,请调用Process.Start

If you want to do this without writing another program, you can create a shortcut file to launch your application with the desired command-line options. 如果要在不编写其他程序的情况下执行此操作,则可以创建快捷方式文件以使用所需的命令行选项启动应用程序。

The format of a shortcut file looks like this: 快捷方式文件的格式如下:

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

For example: 例如:

40#\\Windows\\MyApp.exe parameter1 parameter2

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

From this question (which got it from msdn ): 这个问题 (从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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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