Link to home
Start Free TrialLog in
Avatar of Struggler
Struggler

asked on

How to troubleshooting "Command interpreter cannot be found" error?

I use c function "system" to run some command. However, I got a ENOENT error, which means "Command interpreter cannot be found."

Then I check c:\winnt\system32(it's w2k) folder, CMD.exe is there! and I check the path, no problem. And the command I run do exist, I can open a cmd window then perform it. So, why can't I use "system" function to call it? What am I missed?
Avatar of bastibartel
bastibartel

Hi there,

Can you launch cmd.exe from the Start-Menu ?
Can you use system() with the full path to cmd.exe ?

Cheers,
Sebastian
Avatar of Struggler

ASKER

Hi bastibartel:

     Thanks for your help.
     I can launch cmd.exe from the start  menu;
     system() need to specify cmd.exe or it's full path. c runtime should automatically found the shell and lanuch it.

     btw, the machine has IIS installed, it's a web server. any security setting could prevent system() succeed?
Hi there,

I was just wondering if it's an issue with the environment variable PATH.
If you try to specify the complete path to cmd.exe, we would know.

OK - after you tried the full path, try any other application, like notepad.exe - again with the full path.
I don't think it's a security issue.

If you cannot use system(), try

#include <process.h>
spanwl(_P_NOWAIT,"C:\\windows\\notepad.exe", "notepad.exe", NULL, NULL);
//** doublecheck the path to notepad - it might differ

or cmd.exe, respectively.
The first argument _P_NOWAIT, determines, whether spawn will return immediately or wait til the spawned program has terminated.
The second argument to spawnl is the full path.
The third arg is the usually the name of the program, but it should not matter really.
The fourth, .. arguments are command line parameters, the last argument MUST be NULL)



Cheers,
Sebastian
Hi Struggler

Have you had any success with my siuggestions ?

Cheers,
Sebastian
Hi Sebastian:

      Thanks for your suggestion. What I need is not to change my code, but to find why it doesn't work in customer's Env. And eventually I found that, in customer's env, his COMSPEC variables is not correctly configured. c run-time lib needs this variable to know which shell it could used.

       Now the problem have solved completely. Thanks for the help you've given.

To others want to know more about this:
I've states all this in my blog:http://blog.aarony.net, but it's in chinese.
Congratz to you for finding it then ;-)

So the answer would be ( for all those not fluent in Cantonese)

If the function system() cannot find the command interpreter cmd.exe and hence returns ENOENT,
then check your ComSpec environment variable.

Cheers,
Sebastian

ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial