簡體   English   中英

如何用命令運行程序?

[英]how to run program with command?

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

例如: RunMe.exe trueRunMe.exe false

如果程序返回true,則程序將執行某些操作,並且如果程序返回false

該程序將執行其他操作。

我該怎么做呢?

您的問題不清楚。

如果要編寫這樣的程序,請對Main()使用string[] args參數。
(或調用Environment.GetCommandLineArguments()

如果要運行這樣的程序,請調用Process.Start

如果要在不編寫其他程序的情況下執行此操作,則可以創建快捷方式文件以使用所需的命令行選項啟動應用程序。

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

[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

這個問題 (從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