我已經生成了一個控制檯應用程序,並嘗試通過向其傳遞參數來使用批處理文件運行控制檯應用程序。當我嘗試運行批處理文件時,出現如下錯誤。但是,當我在命令提示符中導航到應用程序位置並傳遞參數時,應用程序運行正常。找不到路徑問題的一部分
C:\WINDOWS\system32>"C:\Users\Akgem\Desktop\Infos\Logs.exe" "1.2.0.2"
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WIND
OWS\system32\Infos\LogInfo.log'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I
nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o
ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea
n useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean
bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean che
ckHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encodin
g, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding
encoding, Boolean checkHost)
at System.IO.File.WriteAllText(String path, String contents)
at GatherLogs.Program.Logentries(String text)
at GatherLogs.Program.Main(String[] args)
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WIND
OWS\system32\Infos\LogInfo.log'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I
nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o
ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea
n useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean
bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean che
ckHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encodin
g, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding
encoding, Boolean checkHost)
at System.IO.File.WriteAllText(String path, String contents)
at GatherLogs.Program.Main(String[] args)
批處理文件內容爲:
"%~dp0Logs.exe" "1.2.0.2"
pause
誰能幫我解決這個問題?
在此先感謝。
找不到路徑'C:\ WINDOWS \ system32'的一部分\相關信息\ LogInfo.log」。意味着沒有找到該目錄。在發佈之前,請自己閱讀整個堆棧跟蹤。 – Peter
您能否顯示正在執行的代碼? –
@Peer試圖從桌面位置(C:\ Users \ Akgem \ Desktop \ Infos \ Logs.exe)運行開發的應用程序。而不是採取路徑(C:\ Users \ Akgem \ Desktop \ Infos \\ LogInfo.log),檢查'C:\ WINDOWS \ system32 \ Infos \ LogInfo.log位置中的日誌文件。這是什麼混淆和創建問題在這裏 –