473,409 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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 12241
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
2
by: Greg Bacchus | last post by:
Hi, I'm getting an exception that really has me stumped. It's sporadic at best, it's only happened a handful of times. This particular time it happened when the user pressed 'Alt-S' to save the...
11
by: Andreas Wirén | last post by:
Hi I'm a C# .NET newbie doing a minor school project but I'm getting a strange error message. 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object...
3
by: Ladvánszky Károly | last post by:
Although I have added a reference to System.Drawing, the following declaration produces a compile error: System::Drawing::Bitmap* b; // error C2039: 'Drawing' is not a member of 'System' ...
13
by: Alexandra | last post by:
Hi, I have a hidden system file that I need to read. I am logged in as an administrator. I can not change the file attributes using the windows explorer.
8
by: Michael | last post by:
I am running a web server (IIS) on Windows 2003 SP 1. My ASP.NET C# applications run fine. However, my application is a combination of Classic ASP and C#. For some reason when you attempt to...
10
by: Reggie | last post by:
I have been using the system() command to write the results of a program to a file. This is being accomplished by the following when running netstat for example: system("netstat example.txt");...
8
by: BVS | last post by:
I am moving from c++ to c# and I have been converting code to c# I have not been able to convert the following code: SYSTEM_INFO siSysInfo; GetSystemInfo(&siSysInfo); SystemID =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.