system() produces error.

J

Jamie Ruff

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?
 
G

Godzilla

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
 
J

Jamie Ruff

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.
 
P

Purl Gurl

Jamie said:
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
 
J

Joe Smith

Jamie said:
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
 
J

Joe Smith

Purl said:
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.

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
 
P

Purl Gurl

Joe said:
Purl Gurl wrote:
(snipped)


That document is out-of-date. While what it says is true:

Then that document is not out of date. You are
contradicting yourself.

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
 
J

Joe Smith

Purl said:
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.
Information in that document holds true, today.

So you're saying that version 5.005_62 is the newest?
-Joe
 
P

Purl Gurl

Joe said:
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
 
P

pete

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.
 
N

Nathalie

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
 
T

thundergnat

Nathalie said:
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.
 
N

nobull

Nathalie said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top