I have generated a console application and tried to run the console application using batch file by passing the arguments to it. When i tried to run the batch file, i got an error like below. But, the application runs fine when i navigate to the application location in command prompt and pass the argument.
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)
Batch file content is :
"%~dp0Logs.exe" "1.2.0.2"
pause
Could anyone please help me to resolve the problem?
Thanks in Advance.