开发者

Can't spawn "cmd.exe"

I use a program called LF-Aligner that uses dictionaries to make parallel texts out of texts in different languages. I believe it's written in Perl. It's based on another program called Hunalign.

When I used it a few months earlier, it worked perfectly. It got accidentally deleted, I recently reinstalled it, but now I just get the error message:

Aligning...

Dictionary used by Hunalign: es-en.dic

Can't spawn "cmd.exe": No such file or directory at script/LF_aligner_2011_06_29_multi.pl line 1856.
Use of uninitialized value $alignedfilesize in numeric eq (==) at script/LF_aligner_2011_06_29_multi.pl line 1864.

-------------------------------------------------

Align failed (probably due to one file being empty or very short). ABORTING...

I can't understand it. Could it be a conflict with something I've installed in the meantime? Or something I've deleted, maybe?

(The problem is not due to "one file being empty or very short", as the program suggests. The files are just fine.)

EDIT: Here is the log file:

Program: LF aligner, version: 2.56, OS: Windows, launched: 2011/09/28, 04:13:01

Setup: filetype_def: t; filetype_prompt: y; l1_def: en; l2_def: hu; l1_prompt: y; l2_prompt: y; segmenttext_def: y; segmenttext_prompt: y=; cleanup_def: y; cleanup_prompt: y; review_def: x; review_prompt: y; create_tmx_def: y; create_tmx_prompt: y; l1_code_def: EN-GB; l2_code_def: HU; l1_code_prompt: y; l2_code_prompt: y; creationdate_prompt: y; creationid_def: ; creationid_prompt: y; ask_master_TM: n; chopmode: 0; tmxnote_def: ; tmxnote_prompt: y; pdfmode: y

GUI on
filetype: t
Input file 1: kakeen.rtf (C:/Users/jippi/Desktop/qewr/kakeen.rtf)
Input file 2: kaketo.rtf (C:/Users/jippi/Desktop/qewr/kaketo.rtf)
Input file sizes: 1375014 bytes 1375014 bytes
Converting rtf files to txt; AbiWord binary: C:\Program Files (x86)\LF_aligner_2.56\aligner\scripts\abiword\bin\AbiWord.exe
Converti开发者_如何学编程ng rtf files to txt; AbiWord binary: C:\Program Files (x86)\LF_aligner_2.56\aligner\scripts\abiword\bin\AbiWord.exe
File sizes after conversion to txt: 1074504 bytes 1074504 bytes
Initial stats: 
- en: 6091 segments,    196644 words,   1037434 chars
- en: 6091 segments,    196644 words,   1037434 chars
Segmentation: y

(The problem occurs when I use txt-files aswell.)


I downloaded the application in question. It is a Perl application packed using pp.

To see the code in question, unzip the downloaded file and then extract the contents of the executable using

E:\Home\Downloads\LF_aligner_2.56_win\aligner> unzip LF_aligner_2.56.exe -d some-temp-dir

You'll find the file

some-temp-dir\script\LF_aligner_2011_06_29_multi.pl

Line 1856 is:

system ("\"$hunalign_bin\" -text \"$scriptpath/scripts/hunalign/data/$hunalign_dic\" \"$folder/$file1\" \"$folder/$file2\" > \"$folder/aligned_${alignfilename}.txt\"");

which is messy to say the least. The program does not check if the system succeeded. Because the system fails, the subsequent attempt to read the size of the output file also fails (note the warning) and subsequently, the program realizes something went wrong:

# SEE IF ALIGNED FILE IS OK, ABORT IF NOT

my $alignedfilesize = -s "$folder/aligned_${alignfilename}.txt";
if ($alignedfilesize == 0) {
    print "\n\n-------------------------------------------------";
    print "\n\nAlign failed (probably due to one file being empty or very short). ABORTING...\n\n";
    print LOG "\nAligned file empty, aborted.";

None of this solves your problem, but gives you something to investigate if you feel like it. At the very least, you might want to notify the author of the program.

The way the author handles paths is too messy for anyone else to feel really motivated to investigate.


Are you launching it from the %WINDIR%\system32 folder? Did you check to see if the PATH environment variable was modified by the installation?


I'm the author of LF Aligner. Frankly, I'm a bit baffled by the "can't spawn cmd.exe" error. Unless that's some incorrect error message, then the problem seems to be outside of LF Aligner itself. You could try and see if the error is indeed due to one file being much shorter than the other. This would cause Hunalign to abort as it's impossible to do a reasonable job of pairing up the sentences, and then LF Aligner stops with the error message you posted. Other than that, it could be some bug in Hunalign (unlikely) or LF Aligner (a bit less unlikely, but I'd still be surprised). As a test, try to align two files that are of the same size, e.g. the same file under two different names.

I could try and do some troubleshooting, let me know which script you are using (and which version). Posting the log file wouldn't hurt, either.

Re: the comments on code quality; I'm not a professional programmer and this is a hobby project. I know it's messy and inelegant, but it works.


Sorry, I know this is super-old and maybe it has already been answered, but I've just found out on Windows if you use the built-in Perl function system() to spawn an executable, and that executable then returns a negative exit value, Perl spews out that erroneous Can't spawn ... message.

I'm using Perl v5.14.2, so this may or may not have been fixed in a later Perl version.


There are multiple reasons why you may get Can't spawn "cmd.exe": ... with Perl on Windows (that is, assuming that you can successfully invoke cmd.exe from a command prompt or from

Can't spawn "cmd.exe"

+R to begin with):

  1. As pointed out previously, PATH may not exist (or no longer exist) in Perl's environment at the time of system/`STRING` invocation, or it may be that PATH is malformed, or that none of the directories in PATH actually contain a cmd.exe at the time of system/`STRING` invocation
  2. PATH may exist and one of the directories therein may contain cmd.exe (or some cmd.exe), but there may be other issues with that particular cmd.exe (e.g. permission issues, DLL issues, etc.)
  3. The invocation of cmd.exe actually succeeded, but some other executable in the command line you passed to system/`STRING` (and spawned as a child by cmd.exe, e.g. hunalign.exe) died abnormally (without invoking DrWatson) and returned an exit code (such as the exception value for an unhandled exception that caused the process to terminate) that Perl then misinterpreted as a misfire of cmd.exe itself

You can easily pinpoint which of the scenarios above using Process Monitor.

Start by setting up a filter in Process Monitor to include events where Path contains cmd.exe and Event Class is File System as well as Event Class is Process.

  1. Has Windows looked for cmd.exe (looking at e.g. IRP_MJ_CREATE) in all directories normally present in PATH up to and including e.g. C:\windows\system32 (or C:\windows\SysWOW64 as the case may be)?
  2. If Windows has located C:\windows\system32\cmd.exe (or C:\windows\SysWOW64\cmd.exe as the case may be), is there anything other than SUCCESS in the Result column? (e.g. indication of permission issues?) Is there a Create Process event for cmd.exe that succeeded? A Load Image event that succeeded?
  3. Writing down the PID number from the Detail column corresponding to the successful Create Process event, and disabling the filters I mentioned above replacing them with a single PID is filter, what is the value for Exit Status in the Detail column corresponding to the Process Exit for the written down PID; is it e.g. e negative value such as -1073741819 (0xc0000005)?


this means the Path c:\windows\system32 is missing in you system environment variable, in order to solve this problem,go to my computer\properity\advance\environment variable,go to the table system variable, edit path, add the path c:\windows\system32


Found this answer on another site, seems the %SystemRoot% variable doesn't always get expaneded in perl, so you need to set the exact path. The below explanation is from this 'greenstone' software wiki, but can be generalized for the problem you're having here.

Windows Building error: can't spawn cmd.exe When building a collection in GLI on Windows, if you see an error message like the following in the build log output: Can't spawn "cmd.exe": No such file or directory … then try the steps below. This error has been reported by some users. It appears to occur because %SystemRoot%, an environment variable used in the %PATH% which evaluates to C:\windows, isn't being passed in to the perl code from GLI. As a result, the PATH does not contain c:\windows\system32 which contains cmd.exe used by perl to execute commands. However, this problem does not appear to manifest for all Windows users of Greenstone.

The solution that has worked for the 2 members of the mailing list who reported this problem is as follows.

  1. In a text editor, open the file gli.bat which is located in your Greenstone installation's "gli" folder

  2. Near the top, just after set GLILANG=en add the following line: set PATH=c:\windows\systems32;%PATH% The above manually prefixes c:\windows\systems32; to the PATH during GLI's execution.

  3. Now try running GLI and building the collection again.


I faced this issue when my folder had "-" or hyphen in its name, probably perl interpreted this as a command instead of folder name, replaced the hyphen with underscore and it started working fine.


Make sure your perl 32/64bit version and your starting cmd version match.

I had the same problem, and for me It was executing a 64-bit perl version inside a 32-bit cmd.exe.

Then, the perl script tried to do a system call, and at that point, it failed with the Can't spawn "cmd.exe" message.

When using a 32-bit perl, all worked.


PATH was already checked, but I got the same error with our software and you can reproduce it with the following:

c:\temp>set path=C:\Windows;C:\%SystemRoot%\system32;C:\Windows\System32\Wbem
c:\temp>perl -w -e "system('dir', 'C:\\');"
Can't spawn "cmd.exe": No such file or directory at -e line 1.

The problem is, that "cmd.exe" could not be found in the PATH... I think unexpanded variables could be a general problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜