c# - 使用参数启动程序

标签 c# command-line command-line-arguments

如何编写一个非常简单的程序,使用命令行导航到用户 Program Files 目录中的程序,然后启动带参数的 .exe?例如:

"C:\etc\Program Files\ProgramFolder\Program.exe C:\etc\desktop\file.spp C\etc\desktop\file.txt"

这会启动一个程序,其中包含某个项目文件和一个 .txt 文件。

最佳答案

您可以使用 ProcessStartInfo.Arguments属性来指定程序的参数字符串:

ProcessStartInfo startInfo = new ProcessStartInfo();        
startInfo.FileName = @"C:\etc\Program Files\ProgramFolder\Program.exe";
startInfo.Arguments = @"C:\etc\desktop\file.spp C:\etc\desktop\file.txt";
Process.Start(startInfo);

关于c# - 使用参数启动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5168612/

相关文章:

c# - SimpleInjector 为 RegisterManyForOpenGeneric 重复注册,以实现具有多个接口(interface)的实现

linux - 用于删除文件中单词的 Shell 脚本

ruby-on-rails - 回滚特定迁移而不回滚其他迁移

windows - Magnify.exe 命令行参数

c# - 为什么未使用的事件参数需要赋值?

c# - 将分隔字符串转换为二维数组

command-line - 大于命令行中的值

c# - 在 C# 中使用子命令解析命令行

c - 在尝试运行 C pthread 程序的命令行中出现权限被拒绝错误

c# - 为什么这个简单的两个 double 计算不准确?