gpt4 book ai didi

c# - C#中的批处理文件执行

转载 作者:行者123 更新时间:2023-12-04 06:26:36 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:




10年前关闭。




Possible Duplicate:
batch file execution in c#



我正在使用 c# 运行 Java 批处理文件..
但问题是,它没有走这条路
我在代码中使用:
 var si = new ProcessStartInfo();
si.CreateNoWindow = true;
si.WorkingDirectory = batch_process_path;
si.FileName = batch_process_path + "\\" + "run.bat";
si.UseShellExecute = true;
Process.Start(si.FileName);

根据我的逻辑,该过程应该从 si.working 开始目录。但它是从“C:”开始的。但是如果我给出静态路径,它将成功执行..
我无法理解问题是什么。
请帮帮我。

最佳答案

请勿使用 batch_process_path + "\\" +改为使用 Path.Combine()以确保路径正确安装斜线。

还有 read this “当 UseShellExecute 为真时,WorkingDirectory 属性指定可执行文件的位置”

所以将其设置为false。

关于c# - C#中的批处理文件执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5979690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com