简体   繁体   English

如何在命令提示符下使用process.StartInfo.Arguments?

[英]How to use process.StartInfo.Arguments in command prompt?

I wanted to use my c# visual studio to open command prompt using process.StartInfo.FileName and process.StartInfo.Arguments to give commands automatically however this does not work out. 我想使用c#visual studio使用process.StartInfo.FileName和process.StartInfo.Arguments打开命令提示符以自动提供命令,但是这无法解决。 Anyone knows how to do this? 有人知道该怎么做吗? ( I am using the cmd to call for my python script ) (我正在使用cmd来调用我的python脚本)

Try using the following. 尝试使用以下内容。 Hope this helps. 希望这可以帮助。 Replace notepad.exe with something else you like. 用其他您喜欢的东西替换notepad.exe。

   Process p = new Process();
   p.StartInfo = new ProcessStartInfo("cmd.exe", "/c notepad.exe");
   p.Start();

Please refer to http://ss64.com/nt/cmd.html for more details. 有关更多详细信息,请访问http://ss64.com/nt/cmd.html

This opens notepad and a file called foo 这将打开记事本和一个名为foo的文件

var procInfo = new ProcessStartInfo("notepad");
        procInfo.Arguments = "foo.txt";
        var proc = new Process();
        proc.StartInfo = procInfo;
        proc.Start(); //Actually executes the process
        proc.WaitForExit(); //Waits until the process completes, in this case, when you close notepad

So for your thing you would call the python interpreter and pass the python script as arguments, along with anything else the interpreter needs (I have 0.1% knowledge of python) 因此,对于您而言,您将调用python解释器并将python脚本作为参数以及解释器需要的其他任何参数传递(我对python的了解为0.1%)

Important note: Make sure your executable is in the path. 重要说明:确保可执行文件在路径中。

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

相关问题 如何使用 process.startInfo.Arguments 传递多个参数 - How to pass multiple argments with process.startInfo.Arguments 用Process.StartInfo.Arguments启动bluestacks - start bluestacks with Process.StartInfo.Arguments 带文本框的多个Process.StartInfo.Arguments - multiple Process.StartInfo.Arguments with textbox Process.StartInfo.Arguments 是否支持 UTF-8 字符串? - Does Process.StartInfo.Arguments support a UTF-8 string? 在process.startinfo.arguments中添加/ C开关后,cmd.exe进程不会启动隐藏启动 - Cmd.exe process does not launch hidden after adding /C switch in process.startinfo.arguments 在C#中将Process.StartInfo.Arguments作为字符串传递,该字符串内部包含双引号(“) - Passing Process.StartInfo.Arguments in C# as a string that contains double-quotes (") within itself 如何从savefiledialog获取完整路径并在“startInfo.Arguments”中使用? - How to get full path from savefiledialog and use in “startInfo.Arguments”? 的System.Diagnostics.Process(); StartInfo.Arguments使用环境变量作为参数 - System.Diagnostics.Process(); StartInfo.Arguments use Environment Variables as argument Process.Start 和 Process.StartInfo 未正确传递 arguments - Process.Start and Process.StartInfo not passing arguments properly startinfo.arguments有问题吗? - startinfo.arguments question?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM