News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

cannot run .exe file from File Explorer

Started by TageB, December 15, 2017, 02:06:51 PM

Previous topic - Next topic

TageB

Windows 10

CodeBlocks installed under D:\CodeBlocks\
path added:  D:\CodeBlocks\MinGW\bin
Simple printout program is saved under D:\C-lib\progr1

Executes in CodeBlocks and in PC Shell ./prog1, but when trying to execute it in File Explorer (as administrator) a window pops up and closes immediately.
I have all permissions to the prog1.exe file. Virus program has also been turned off.

Why can't I run my prog1.exe file from File Explorer?

stahta01

#1
Try running it from an cmd.exe prompt.
Does it work?

Edit: Added link to fix the most common user mistake https://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042856625&id=1043284385

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

TageB

It works in Code::Blocks, PowerShell (sorry I wrote PC Shell) and it works in cmd.exe.

I could not find any help in you link. I have installed the latest Code::Blocks and everything seems to work, except the built and compiled exe file, executed from File Explorer.

sodev

You have build a console application that does some output and terminates then on its own. What explorer does is open a shell, run the program, and close the shell again after the program terminates. So what you are seeing is absolut normal and correct behavior.

Don't like it? Either prevent your application from terminating itself or write a simple wrapper shellscript that starts your program and pause's after it. Or simply start it manually in a shell like you already did.

TageB

I got something from Tim's link. Thank you.

If I add 'getchar()' before the 'return 0' the window will stay open, showing the result, until I press enter.
But then I have to use 'enter' to quit the program, which wasn't the case when running it before in terminal.

So I would like a solution that shows the result and end the program, as in terminal.

TageB

OK sodev,
I was writing a reply when your answer arrived so I didn't see it.
As I understand you, there is no way to run the program, keeping the result window open, and quitting the program from File Explorer.

TageB

sodev,
Could you or someone else give med give me an example of a shell script I could run from File Explorer.
Suppose it should have the exe file as an argument, open a shell, running the exe file from shell, and then the program ends and the shell stays open? I am not used to good shell scripting...

sodev

Well, a very basic solution with hardcoded application name that requires the application to be in the current working directory (which explorer sets to the directory of the script) would be like this:

launch1.cmd

@echo off
prog1.exe
pause


The premium version with hardcoded default application name and optional specified as command line parameter and the possibility to launch with a random working directory (but the application must be in the same directory of the script) would be like this:

launch2.cmd

@echo off
set APPLICATION=prog1.exe

set BASEDIR=%~dp0
if not "x%1" == "x" set APPLICATION=%1

"%BASEDIR%%APPLICATION%"
pause


TageB