469,330 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

system() produces error.

I am having problems with making system calls on Windows under Cygwin
that involve the use of redirection operators and pipes. For example,
the line below will cat two files, but the next command will not
append the first file to the end of the second as expected and issues
the error "Can't spawn "cmd.exe": No such file or directory at line
x". If I issue the append command manually on the command line, then
it works fine.

system("cat file1 file2"); # works fine
system("cat file1 >> file2"); # where is cmd.exe?

Since the first command works, I assume that the path to 'cmd.exe' is
set correctly within the program as system always uses cmd.exe to run
commands.

If I use ``'s, then I do not get the error, but the command still does
not execute.

One possible explanation, is that since I am using Cygwin on Windows
to allow the script to run UNIX style commands, Perl may be having
problems with that. The question being how do I test for this?
Jul 19 '05 #1
12 11956
Jamie Ruff wrote:

(snipped)
the error "Can't spawn "cmd.exe": No such file or directory at line If I issue the append command manually on the command line, then
it works fine.
I am curious to read your syntax for appending from a command line.

system("cat file1 >> file2"); # where is cmd.exe?


That is the same as,

copy file1>>file2

Which will cop a system error, "File cannot be copied onto itself"

You are trying combine file1 and file2 then write the results to file1.

copy file1+file2 file3

Note that will append a \x1a line ending to your file3 print.
system ("type file1>>file2");

Do not use a die with that syntax when using Perl.
What command line syntax are you using which successfully
appends one file to another file?
Purl Gurl
Jul 19 '05 #2
> What command line syntax are you using which successfully
appends one file to another file?
Purl Gurl


I am using the UNIX command that is available through cygwin. For
example, if I have these two files:

file1.txt
Only line of file 1.

file2.txt
Only line of file 2.

and type in a cmd window with the cygwin\bin path set properly the
following:
cat file1.txt >> file2.txt

file2.txt will now look like this:

file2.txt
Only line of file 2.
Only line of file 1.

which is what I am looking for (this is what I tried manually to prove
to myself that I was not going insane or doing something stupid). I
do not want to use the DOS 'type' command because I eventually want to
port this to run directly on UNIX without having to do any recoding.
The problem appears to be using any redirection or pipes in a system
command when that system is making use of the cygwin binaries on a
Windows system.
Jul 19 '05 #3
Jamie Ruff wrote:
Purl Gurl wrote: I am using the UNIX command that is available through cygwin. For
example, if I have these two files:


No, you are using emulation of Unix commands. Regardless
of which emulated Unix commands you invoke, it is your
Win32 system which performs the tasks.

Set an Environment Path to your cygwin in your Perl script,
then run your commands. If this fails, use a full path
to your cygwin executable. Reads you are invoking a
Perl script which is outside the path for cygwin.

Possibly, you do not have Perl configured correctly for
use with cygwin.

There are known issues with cygwin. It is a nice program
but for many circumstances, cygwin causes more problems
than are resolved.

http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html

http://www.xav.com/perl/lib/Pod/perlcygwin.html
Purl Gurl
Jul 19 '05 #4
Jamie Ruff wrote:
system("cat file1 file2"); # works fine
system("cat file1 >> file2"); # where is cmd.exe?

Since the first command works, I assume that the path to 'cmd.exe' is
set correctly within the program as system always uses cmd.exe to run
commands.


No, it does not. Check the docs for system() again.

For simple command strings, like the first one, perl executes the
other program itself. Only for command strings with meta characters
(such as ">>") will perl use a shell.

It appears that you are not running the version of perl you think you are.

C:\>\cygwin\bin\perl -MConfig -le "print $^X,' ',$Config{sh}"
/usr/bin/perl /bin/sh
C:\>perl -MConfig -le "print $^X,' ',$Config{sh}"
C:\Perl\bin\perl.exe cmd /x /c

As you can see, the Windows native version of perl.exe uses "cmd"
and the cygwin version of perl uses "/bin/sh".

Are you sure you're running cygwin's /usr/bin/perl and not the
DOS C:\Perl\bin\perl.exe when it gives you problems?
-Joe
Jul 19 '05 #5
Purl Gurl wrote:
There are known issues with cygwin. It is a nice program
but for many circumstances, cygwin causes more problems
than are resolved.

http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html
That document is out-of-date. While what it says is true:
The problem basically boils down to the fact that cygwin
attempts to offer a UNIX like file-system structure where
absolute path names start with / instead of a windows
style (e.g. c:). ActiveState's perl does not understand
this UNIX style names.
The solution is to use the version of perl that comes with
cygwin instead of ActiveState's perl when running under cygwin.
http://www.xav.com/perl/lib/Pod/perlcygwin.html


Note where it says "snapshots that were expected to stabilize early
in 2000" and refers to perl5.005_62 as the newest. Another
out-of-date document.

-Joe
Jul 19 '05 #6
Joe Smith wrote:
Purl Gurl wrote:
(snipped)
http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html That document is out-of-date. While what it says is true:
Then that document is not out of date. You are
contradicting yourself.

http://www.xav.com/perl/lib/Pod/perlcygwin.html

Another out-of-date document.


Information in that document holds true, today.

You need to pay more attention to what is written,
rather than document dates.
Purl Gurl
Jul 19 '05 #7
Purl Gurl wrote:
http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html
That document is out-of-date. While what it says is true:
Then that document is not out of date. You are
contradicting yourself.


The document is out-of-date because it was implying
that the only version of Perl for Windows is ActiveState's.
Using the cygwin version of Perl under cygwin does not
have the problems that the ActiveState version of perl
has under cygwin.
http://www.xav.com/perl/lib/Pod/perlcygwin.html

Another out-of-date document.


Information in that document holds true, today.


So you're saying that version 5.005_62 is the newest?
-Joe
Jul 19 '05 #8
Joe Smith wrote:
Purl Gurl wrote:


(snipped)

Rather amusing you boys are so insecure, so lacking in
self-confidence, you are psychotically driven to have
the last word no matter how inane is your last word.
Purl Gurl
Jul 19 '05 #9
Purl Gurl <pu******@purlgurl.net> wrote in news:40F9377D.6E6889B9
@purlgurl.net:
Joe Smith wrote:

Rather amusing you boys are so insecure, so lacking in
self-confidence, you are psychotically driven to have
the last word no matter how inane is your last word.
Purl Gurl


And I get the last word of the thread, hurray!
My congratulations to the most well known Perl programmer in the Perl
community for the second place spot.


Jul 19 '05 #10

I too have the error "Can't spawn "cmd.exe": No such file or director
at line "
If I issue the command manually on the command line, then
it doesn't work, but the error "Can't spawn "cmd.exe": No such file o
directory at line" doesn't appear.

In either case, a window opens and tells me that the program UNKNOW
that I've called cannot work properly and that it has to be closed.

My syntax is
system "C:\\Program Files\\Programmes LINKAGE\\unknown";

I know that the UNKNOWN program works properly, because it works on a
other data set.

I call my programs in a dos prompt on Windows.

Thank yo
-
Nathali
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 19 '05 #11
Nathalie wrote:
I too have the error "Can't spawn "cmd.exe": No such file or directory
at line "
If I issue the command manually on the command line, then
it doesn't work, but the error "Can't spawn "cmd.exe": No such file or
directory at line" doesn't appear.

In either case, a window opens and tells me that the program UNKNOWN
that I've called cannot work properly and that it has to be closed.

My syntax is
system "C:\\Program Files\\Programmes LINKAGE\\unknown";

I know that the UNKNOWN program works properly, because it works on an
other data set.


This is only peripherally perl related.
In the DOS command window, when calling parameters have a space in them,
you need to enclose them in double quotes. Try something like:

system "\"C:\\Program Files\\Programmes LINKAGE\\unknown\"";

or even better:

system '"C:\Program Files\Programmes LINKAGE\unknown"';

This news group is doesn't exist. Please use comp.lang.perl.misc in the
future.
Jul 19 '05 #12
Nathalie <Na*************@mail.codecomments.com> wrote in message news:<Na*************@mail.codecomments.com>...
I too have the error "Can't spawn "cmd.exe": No such file or directory
at line "
If I issue the command manually on the command line, then
it doesn't work, but the error "Can't spawn "cmd.exe": No such file or
directory at line" doesn't appear.

In either case, a window opens and tells me that the program UNKNOWN
that I've called cannot work properly and that it has to be closed.

My syntax is
system "C:\\Program Files\\Programmes LINKAGE\\unknown";
If you had typed the contents of that string at the command prompt
manually what would have happend?

You'd have got an error because windows would fail to find
C:\program.exe (or C:\program.cmd or ...)

You need to protect the spaces in the filename exactly as you would if
you typed the command at the prompt or you must use the list form of
system(). Note I don't think you can use the list form without
passing at least one argument so if it is important that you all
unknown.exe with no arguments then the list form is not an option.

This nresgroup does not exist (see FAQ). Please do not reactivate
long-dormant threads here.
I know that the UNKNOWN program works properly, because it works on an
other data set.

I call my programs in a dos prompt on Windows.

Thank you

Jul 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
3 posts views Thread by Richard A. DeVenezia | last post: by
11 posts views Thread by Andreas Wirén | last post: by
3 posts views Thread by Ladvánszky Károly | last post: by
8 posts views Thread by Michael | last post: by
10 posts views Thread by Reggie | last post: by
8 posts views Thread by BVS | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.