[英]Run the .exe file from command prompt
我已經使用Visual Studio在C#中開發了程序,並在Debug文件夾中生成了.exe文件。 我還在“屬性”->“調試”中添加了命令行參數。
傳遞的參數為D:\\ Example \\ bin \\ Release \\ Input_Files \\ D:\\ Example \\ bin \\ Debug \\ trycc.css 900640
通過將解決方案配置標記為Debug來運行此解決方案,它將在Debug文件夾中生成.exe文件。
當我嘗試從命令行運行時,它告訴我,無法打開與.exe位於同一級別的文件。
D:\>D:\Example\bin\Debug\Example.exe D:\Example\bin\Release\Input_Files\ D:\Example\bin\Debug\trycc.css 900 640
我不明白我要去哪里錯了。 請幫助。
這里是 :
D:\>D:\Example\bin\Debug\DFu1.exe "D:\Example\bin\Release\I
nput_Files\" "D:\Example\bin\Release\Input_Files\css\screen.css" "900
" "830"
Incomplete Arguments entered.
Press any key to continue
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part
of the path 'C:\Out\elogs.txt'.
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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at ExampleParser.Program.Main(String[] args) in D:\Example\Program.cs:l
ine 691
可能是您的問題是報價不正確。 嘗試傳遞以下參數:
"D:\\Example\\bin\\Release\\Input_Files\\" "D:\\Example\\bin\\Debug\\trycc.css" 900 640
要么:
"D:\Example\bin\Release\Input_Files\" "D:\Example\bin\Debug\trycc.css" 900 640
似乎您引用的目錄(文件夾) D:\\Out'
不存在,如果正確,則首先確保該目錄存在。 如果不是,則應用程序可能使用相對路徑(例如..\\SomeDir\\
)而不是絕對路徑,因此需要更改代碼才能正確定位此目錄。 證明應用程序有效的一種簡單而快速的方法是,首先將cd放入其所在的目錄,然后從該路徑運行exe:
cd D:\Example\bin\Debug
Example.exe D:\Example\bin\Release\Input_Files\ D:\Example\bin\Debug\trycc.css 900 640
如果您實際上有相對路徑,請記住,如果應用程序(.exe)在D:\\Example\\bin\\Debug
並且您有一個目錄D:\\Example\\bin\\Out
,並且代碼嘗試對該文件進行讀/寫操作使用..\\Out
“ Out”目錄,如果直接從\\ bin \\ Debug運行應用程序,它將成功。 但是,如果您從D:\\MyOtherDir\\Test
運行應用程序(是的,即使您輸入完整路徑D:\\ Example \\ bin \\ Debug \\ Example.exe ),它也會解析為D:\\ MyOtherDir \\ Out ,相對路徑基於當前的工作目錄,而不是exe所在的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.