我正在尝试用 C 而不是 C#(可移植性较差)重写以下程序。很明显,“int system (const char * command)”将是完成程序所必需的。以“int main ( int argc, char * argv[] )”开头将允许获取命令行参数,但仍然存在难以理解的问题。您如何成功转义其中包含空格的参数?在下面的程序中,其中包含空格的参数(例如:screensaver.scr "this is a test")将作为单独的参数传递给脚本(例如:screensaver.scr this is a test)并且很容易导致问题。
namespace Boids_Screensaver
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
System.Diagnostics.Process python = new System.Diagnostics.Process();
python.EnableRaisingEvents = false;
python.StartInfo.FileName = "C:\\Python31\\pythonw.exe";
python.StartInfo.Arguments = "boids.pyw";
foreach (string arg in args)
{
python.StartInfo.Arguments += " " + arg;
}
python.Start();
}
}
}
最佳答案
Windows 乱七八糟。每个程序都有自己的规则。
关于c# - 重定向用于引导的命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1777862/