[英]C# assigning value to variable says it cannot find the file?
我有一個運行批處理文件的非常簡單的方法。 方法是這樣的:
private string _binnPath = Application.StartupPath + "\\Binn";
public void DumpFileSystem(string snapshotFolder)
{
var cwd = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(_binnPath);
var snapshotOutput = Path.Combine(Application.StartupPath, snapshotFolder);
snapshotOutput = Path.Combine(snapshotOutput, DateTime.UtcNow.Ticks + "-files.txt");
var batCommand = _binnPath + "\\DumpFileSystem.bat";
string batFilename = batCommand + " " + snapshotOutput;
using (var process = Process.Start(batFilename))
{
process?.WaitForExit();
}
Directory.SetCurrentDirectory(cwd);
}
批處理文件是這樣的:
dir /s c:\ > %1
在一行上var batCommand = _binnPath + "\\\\DumpFileSystem.bat";
我收到這個:
System.dll中發生了類型為'System.ComponentModel.Win32Exception'的未處理的異常
附加信息:系統找不到指定的文件
這根本沒有意義,因為我只分配了一個變量。 我要做的就是使用snapshotOutput變量運行批處理文件。 這不應該那么困難。
問題
任何想法如何使批處理文件運行? 和
當變量的設置甚至不應該尋找文件時,為什么會引發錯誤?
刪除這些代碼
string batFilename = batCommand + " " + snapshotOutput;
您必須更改流程開始
Process.Start(new ProcessStartInfo(batCommand , snapshotOutput))
請在這里查看: https : //stackoverflow.com/a/5766669/6082960
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.