system()产生错误。 [英] system() produces error.

查看:75
本文介绍了system()产生错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用重定向操作符和管道的Cygwin

下在Windows上进行系统调用时遇到问题。例如,

下面的行将捕获两个文件,但是下一个命令将不会

将第一个文件附加到第二个文件的末尾,并按照预期发布

错误无法生成cmd.exe":行上没有这样的文件或目录

x"。如果我在命令行上手动发出append命令,那么

它可以正常工作。


system(cat file1 file2); #工作正常

system(" cat file1>> file2"); #cmd.exe在哪里?


由于第一个命令有效,我认为''cmd.exe''的路径是

正确设置系统程序总是使用cmd.exe来运行

命令。


如果我使用``'s,那么我没有得到错误,但命令仍然没有执行

.


一个可能的解释是,因为我在Windows上使用Cygwin

到允许脚本运行UNIX样式命令,Perl可能有这个问题的
问题。问题是如何测试?

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?

推荐答案

Jamie Ruff写道:


(剪掉)
Jamie Ruff wrote:

(snipped)
错误无法生成cmd.exe":在
行没有这样的文件或目录如果我在命令行上手动发出append命令,然后
它工作正常。


我很想读你从命令行追加的语法。


system(" cat file1>> file2" ); #cmd.exe在哪里?
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?




这是一样的,


copy file1>> file2


这将导致系统错误,文件无法复制到自身


您正在尝试合并file1和file2然后将结果写入file1 。


复制文件1 +文件2文件3


请注意,会在文件3打印后附加\ x1a行。

system(" type file1>> file2");


使用Perl时不要使用具有该语法的骰子。

什么命令行语法是你成功使用

将一个文件附加到另一个文件?

Purl Gurl



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


>您使用哪种命令行语法
> What command line syntax are you using which successfully
将一个文件附加到另一个文件?

Purl Gurl
appends one file to another file?
Purl Gurl




我正在使用cygwin提供的UNIX命令。对于

示例,如果我有这两个文件:


file1.txt

只有文件行1.


file2.txt

只有文件行2.


并使用cygwin \ bin键入cmd窗口路径设置正确

以下:

cat file1.txt>> file2.txt


file2.txt现在看起来像这样:

file2.txt

只有一行文件2.

只有文件行1.


这就是我要找的东西(这是我试图手动证明的内容

对自己,我不会疯狂或做一些愚蠢的事情)。我不想使用DOS''type''命令,因为我最终希望将这个命令直接在UNIX上运行而不必进行任何重新编码。

当系统在

Windows上使用cygwin二进制文件时,问题似乎是使用系统中的任何重定向或管道

命令系统。



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.


Jamie Ruff写道:
Jamie Ruff wrote:
Purl Gurl写道:
我正在使用可用的UNIX命令通过cygwin。对于
示例,如果我有这两个文件:
Purl Gurl wrote: I am using the UNIX command that is available through cygwin. For
example, if I have these two files:




不,您正在使用Unix命令的模拟。无论你调用哪个模拟Unix命令的
,它都是你执行任务的
Win32系统。


设置一个环境在Perl脚本中使用cygwin的路径,然后运行命令
。如果失败,请使用完整路径

到您的cygwin可执行文件。读取你正在调用一个

Perl脚本,它位于cygwin的路径之外。


可能,你没有正确配置Perl

与cygwin一起使用。


cygwin存在已知问题。这是一个很好的程序

但是在很多情况下,cygwin导致的问题比解决的问题多得多。

http://www.cs.unc.edu/~jeffay/dirt/ FAQ / cygwin-perl.html
http://www.xav.com/perl/lib/Pod/perlcygwin.html

Purl Gurl



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


这篇关于system()产生错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆