我已经生成了一个控制台应用程序,并尝试通过向其传递参数来使用批处理文件运行控制台应用程序。当我尝试运行批处理文件时,出现如下错误。但是,当我在命令提示符中导航到应用程序位置并传递参数时,应用程序运行正常。找不到路径问题的一部分
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位置中的日志文件。这是什么混淆和创建问题在这里 –