我正在尝试通过 C# 和命令行运行软件的批处理实用工具,但无法让它工作。当我将其复制并粘贴到命令提示符中时,我能够构建一个正确且有效的字符串,但是当我的代码尝试自动执行该步骤时,什么也没有发生;脚本只是运行到最后,什么也没有发生。
作为参考,这就是我想要做的: https://knowledge.autodesk.com/support/navisworks-products/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/Navisworks/files/GUID-14B017E2-B4A2-432F-8C2D -1F1856EECB8E-htm.html
我已经尝试过一些多次更改 StartInfo 的不同属性,但到目前为止没有任何效果。正在运行的不同目录是否存在问题?
- “filesTextFile”是 C: 驱动器上的一个 .txt 文件,其中列出了位于共享网络驱动器 (\\{network}\) 上的文件的路径
- cmd.exe 位于 C: 驱动器中
- “NWBatchUtilityLoc”变量是C: 驱动器上的 .exe
- .cs 脚本正在从 D: 驱动器运行。
这是我的代码摘录,显示了如何构建字符串以及如何使用 System.Diagnostics.Process。
var utilityCmd = $@"""{NWBatchUtilityLoc}"" /i ""{filesTextFile}"" /osd /log ""{logDir}"" /lang en-US";
var p = new Process
{
StartInfo =
{
FileName = @"C:\Windows\System32\cmd.exe",
Arguments = "/C " + utilityCmd,
}
};
p.Start();
I'm trying to run a software's batch utility tool via C# and the command line but am not able to get it to work. I am able to build a string which is correct and works when I just copy and paste it into the command prompt, but when my code tries to do that step automatically nothing happens; the script just runs to the end and nothing happens.
For reference, this is what I'm trying to do: https://knowledge.autodesk.com/support/navisworks-products/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/Navisworks/files/GUID-14B017E2-B4A2-432F-8C2D-1F1856EECB8E-htm.html
I've tried a number of times changing the different properties of StartInfo, but nothing has worked so far. Could there be an issue with the different directories that are at play?
- "filesTextFile" is a .txt file on the C: drive which lists paths for files located on a shared network drive (\\{network}\)
- cmd.exe is in the C: drive
- "NWBatchUtilityLoc" variable is the file path for an .exe on the C: drive
- .cs script is running from the D: drive.
This is an excerpt of my code that shows how the string is being built and how I am using System.Diagnostics.Process
.
var utilityCmd = $@"""{NWBatchUtilityLoc}"" /i ""{filesTextFile}"" /osd /log ""{logDir}"" /lang en-US";
var p = new Process
{
StartInfo =
{
FileName = @"C:\Windows\System32\cmd.exe",
Arguments = "/C " + utilityCmd,
}
};
p.Start();
发布评论