使用来自文本文件的参数运行exe

本文关键字:参数 运行 exe 文件 文本 | 更新日期: 2023-09-27 18:12:47

正如标题所说,我正在尝试运行带有来自TXT文件(在资源中)的参数/参数的EXE,我知道如何使用参数启动程序,但不是TXT参数。这就是我所做的,但似乎不工作!

private void btnStart_Click(object sender, RoutedEventArgs e)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat("RustClient.exe"));
        startInfo.Arguments = @"Resources'arguments.txt";
        startInfo.UseShellExecute = false;
        System.Diagnostics.Process.Start(startInfo);
    }

它启动程序,但不包含我在txt文件中设置的参数。

如果我想从TXT文件中读取它们,是因为我希望它们是可编辑的。基本上,我的程序将是一个简单的方法来编辑启动选项的家伙谁不知道他们

我是个编程新手这是我的第一个编程项目,所有东西都得谷歌^^

使用来自文本文件的参数运行exe

首先从文件中读取参数文本,然后将其分配给参数

private void btnStart_Click(object sender, RoutedEventArgs e)
    {
        string arg = File.ReadAllText("text file location");
        ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat("RustClient.exe"));
        startInfo.Arguments = arg;
        startInfo.UseShellExecute = false;
        System.Diagnostics.Process.Start(startInfo);
    }

我试图读取一个使用input.txt作为参数的exe文件,我已经尝试了来自各种链接的多种解决方案,包括上面的一个。同样的exe文件,当通过命令窗口传递input.txt作为参数时,会给我正确的输出,但在visual studio上,它不会给我任何输出。我是新手,帮帮我吧。下面是代码:>

using System;
using System.Diagnostics;
namespace MyApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Process process = new Process();
            process.StartInfo.FileName = @"C:'Users'khannapr'decoder_test'dist'test.exe"; // Replace with the actual path to test.exe
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.Start();
            // Read input from the input.txt file
            string input = System.IO.File.ReadAllText(@"C:'Users'khannapr'decoder_test'input.txt"); // Replace with the actual path to input.txt
            // Write input to the process
            process.StandardInput.WriteLine(input);
            process.StandardInput.Close();
            // Read output from the process
            string output = process.StandardOutput.ReadToEnd();
            Console.WriteLine(output);
            process.WaitForExit();
        }
    }
}

我还试图将输入文件作为VS的调试选项中的命令行参数传递,我还试图用{"/","//",",",",任何其他可能的方式来构建我的路径}我使用的VS版本是2019