Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

php - Windows CMD.exe "The system cannot find the path specified."

Solved by restoring Windows to previous state

The message (The system cannot find the path specified.) shows...

1) When i open new CMD (Win+R => cmd). It starts with introduction. (on line 3)

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
The system cannot find the path specified.

C:UsersViliamKopecky>

2) When i execute some command like cmd /C dir (or cmd /C php -v or whatever) (on line 2)

C:UsersViliamKopecky>cmd /C dir
The system cannot find the path specified.
 Volume in drive C is Windows7_OS
 Volume Serial Number is 8230-1246
...

C:WindowsSystem32>cmd /C php -v
The system cannot find the path specified.
PHP 5.4.8 (cli) (built: Oct 16 2012 22:30:23)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

3) (the most annoying) when i run exec function from PHP or Node.js or probably any scripting lang. (which are probably runned from inside as cmd /C <command>)

The message does not show...

1) when i execute the command right from the cmd (or mingw, ...)

C:UsersViliamKopecky>dir
 Volume in drive C is Windows7_OS
 Volume Serial Number is 8230-1246

 Directory of C:UsersViliamKopecky

Let's start with simple command from cmd.

php -r "exec('dir', $stdout, $stderr); print(implode(" ", $stdout), $stderr);"

and the result is like this (the directory test is empty - that is correct):

E:est>php -r "exec('dir', $stdout, $stderr); print(implode("
", $stdout), $stderr);"
The system cannot find the path specified.
 Volume in drive E is www
 Volume Serial Number is 0C99-95EC

 Directory of E:est

09.11.2012  22:42    <DIR>          .
09.11.2012  22:42    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  13?495?296?000 bytes free
int(1)

Which shows that the command dir has is executed from php correctly. Only thing thats wrong is the second line - The system cannot find the path specified. - that should not be there.

This message is output by exec from PHP (and also from Node.js as require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});)

When I execute command right from cmd (or mingw, etc.) it executes correctly without the message. Environment variable PATH seem ok. Problem is just executing from script environment through exec functions.

How to get rid of that annoying message? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is that some program has been set to autorun when you run cmd.exe. In my case it was ANSICON that was installed... and then I moved the file without properly uninstalling.

I found a solution in this blog post:

http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/

The short version is to find

HKCUSoftwareMicrosoftCommand ProcessorAutoRun

and clear the value.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...