簡體   English   中英

為什么下面的 Hello World 程序在 PowerShell 上沒有顯示任何 output? 相同的程序在 CMD 上顯示正確的 output

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM