Console applications with a file association start a new cmd window. This is unhelpful.
I have a simple win32 console application (example.exe) which just printf's all its arguments. In the windows registry I've set up a file association so that the file extension ".myfile" invokes "example.exe %1".
In a CMD window running .\example.exe file.myfile displays the output in the cmd window. (this is good)
In a CMD window running .\file.myfile invokes example.exe and displays the output in the cmd window. (this is good)
In a Powershell window running .\example.exe file.myfile displays the output in the powershell window. (this is good)
In a powershell window running .\file.myfile opens a new cmd window, in which example.exe is run, and the output is printed. The cmd windows then closes. (this is NOT good). The console application should run inside the powershell window.
John Daintree commented
The application does write to stdout (the code follows), and if I run it directly in the powershell console the output appears there. The problem is that if it's opened by the association with a file extension a separate CMD window is opened to run it. That behaviour is different to what I see in CMD which runs the application in the same window.
void main(int argc, char **argv)
for (int i=0;i<argc;i++)
for (int i=0;i<10;i++)
Terry Wrennall (Black V) commented
This is your app, it needs to output to stdout
take hostname.exe or ipconfig.exe for example, both of those launch an external process and return it to powershell
try also cmd.exe /c echo test that also outputs to console