[英]Why is the following Hello World program not showing any output on PowerShell ? The same program show correct output on CMD
好的,這是一個 C++ .NET 控制台 Hello World 應用程序。
代碼:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World" << endl;
return 0;
}
上述程序在 Visual Studio 中調試時工作正常,並按預期輸出“Hello World”。 當從 CMD 執行程序時,會顯示相同的行為。
但是,當我從 PowerShell 執行這個程序時,什么也沒有發生。 就好像沒有 cout 語句,程序就退出了。 請幫忙
在 powershell 中運行 exe 主要像
& ".\test.exe" arg1 arg2 arg3
有可能
cmd /c "test.exe"
如果你運行你的腳本就像
test.exe
大多數情況下它不會起作用,因為這樣的調用是為path
環境變量中導入的二進制模塊或文件保留的。 .\
代表當前目錄(即gci.\
),因此要運行您的exe
文件,您需要調用該文件
& .\test.exe
& "C:\Program Files\Git\cmd\git.exe"
或者只是沒有&
和完整的路徑
C:\Path\To\File\Without\Spaces.exe
C:\"Program Files"\Git\cmd\git.exe
.\test.exe
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.