Like in CMD, to run a C++ program, I use the command g++ filename.cpp, then I run it using the command a.exe, which opens the output in the CMD itself. How to do such thing using a PowerShell? I am unable to open the file by simple command as a.exe. Am I doing it the wrong way?
3 Answers
It is a best practice to use the invocation operator and to quote the command.
& ".\a.exe" p1 p2 p3
PowerShell will also allow the use of / as the path separator.
& "./a.exe" p1 p2 p3 "p4 with space"
1 Comment
Bill_Stewart
The quotes around
.\a.exe are not required since it does not contain any whitespace.[Working 100%] from a Windows user.
Open the terminal(PowerShell) where your file.cpp is created.
g++ file.cpp//it will compile the file into a.exe.\a.exe//this will run the program in windows..\a.out//this will run the program in linux.
1 Comment
Hydranix
Number 3 will potentially give an error on most linux shells along the lines of
.a.exe does not exist or more dangerously run the file .a.exe which would be a hidden file in the working directory. You likely meant that ./a.exe will work on most linux shells. While, in fact, it also works fine in powershell.
./aStandardInput,StandardOutput, andStandardErrorfile handles -- while the single thread of "CMD itself" simply blocks until a.exe exits.NoDefaultCurrentDirectoryInExePath. With this set, you will also have to use.\ato run a.exe in CMD. But the working directory can still be added explicitly toPATHas ".", which gives you more control over its position in the overall search.