c# - 重定向用于引导的命令行参数

标签 c# python c arguments screensaver

我正在尝试用 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/

相关文章:

python - 如何更改 Django 管理页面的名称?

c - 如果和和两个加数的按位异或均为负,这意味着什么?

c - 多线程 pthread 错误

python - 如何将每个字典值插入列表中相应键之后?

python - 如何组合一维数组来创建一个新数组

c# - 使用 NDepend 查找方法的所有使用(包括通过接口(interface))

c# - IO操作超时

c - 这个复杂的 C 类型声明是什么意思?

c# - 使用 HttpEncoder.HtmlDecode 返回一个 utf-8 字符串?

c# - 当作为函数参数从 Delphi 传递到 C# 时,空字符串变为 null