콘솔 응용 프로그램을 생성하고 인수를 전달하여 배치 파일을 사용하여 콘솔 응용 프로그램을 실행하려고했습니다. 배치 파일을 실행하려고 할 때 아래와 같은 오류가 발생했습니다. 그러나 명령 프롬프트에서 응용 프로그램 위치로 이동하여 인수를 전달하면 응용 프로그램이 제대로 실행됩니다.
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
명령 줄에서 알 수 있듯이 현재 작업 디렉토리는 입니다. 분명히 응용 프로그램은 작업 디렉토리가 C:\Users\Akgem\Desktop\Infos\
(또는 그냥 C:\Users\Akgem\Desktop
) 일 것으로 예상 합니다. 따라서 프로그램을 실행하기 전에이 디렉토리로 변경해야합니다.
cd "%~dp0"
Logs.exe "1.2.0.2"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다