无法在cygwin中执行系统命令 [英] Cannot execute system command in cygwin

查看:319
本文介绍了无法在cygwin中执行系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的perl脚本,我无法在cygwin中执行:

 #!/ usr / bin / perl 

use strict;


系统(../ cat.exe< a.txt> b.txt);

当我运行它时,脚本告诉我:

  ./ my_test.pl 
'..'不能识别为内部或外部命令,
可操作的程序或批处理文件。但是我可以在cygwin shell中运行该命令:


$ b


  $ ../cat.exe < a.txt> b.txt 

$ ../cat.exe b.txt
hello

可执行文件cat.exe存在于上面的目录中,a.txt在当前工作的
目录中。



我的perl版本:
$ perl -v



这是perl,v5.8.8专为MSWin32-x86多线程
(有12个注册补丁, -V for more details)

解决方案

你使用的是一个为Windows构建的perl(ActiveState?Strawberry?版。它为 system()调用 cmd.exe ,它认为 .. 是命令, / 引入了一个选项。



尝试更改 system()调用:

 系统(.. \\cat.exe < a.txt> b.txt); 

但是你应该 通常使用cygwin版本的perl



以下命令的输出是什么?

  echo$ PATH
type -a perl
/ usr / bin / perl -v

从我们目前看到的,看起来你已经安装了一些特定于Windows的Perl及其 perl。 exe 在您的Cygwin / usr / bin 目录中。如果是这样,然后(a)卸载它(你可以重新安装在别的地方,如果你喜欢),和(b)通过Cygwin的 setup.exe



使用警告; 之后添加 use strict; 在你的Perl脚本中,这与你的问题没有关系,但它是好的做法。)


I have the following simple perl script that I cannot execute in cygwin:

#!/usr/bin/perl

use strict;


system("../cat.exe < a.txt > b.txt");

When I run it, the script tells me:

./my_test.pl
'..' is not recognized as an internal or external command,
operable program or batch file.

However I can run the command in the cygwin shell:

$ ../cat.exe < a.txt > b.txt

$ ../cat.exe b.txt
hello

The executable cat.exe exists in the directory above and a.txt in the current working directory.

My version of perl: $ perl -v

This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 12 registered patches, see perl -V for more detail)

解决方案

You're using a perl built for Windows (ActiveState? Strawberry?), not the Cygwin version. It invokes cmd.exe for system(), which thinks that .. is the command and / introduces an option.

Try changing the the system() call to:

system("..\\cat.exe < a.txt > b.txt");

But you should normally be using the Cygwin version of perl when running a script from bash.

What is the output of the following commands?

echo "$PATH"
type -a perl
/usr/bin/perl -v

From what we've seen so far, it looks like you've installed some Windows-specific Perl with its perl.exe in your Cygwin /usr/bin directory. If so, then (a) uninstall it (you can reinstall it elsewhere if you like), and (b) re-install the "perl" package via Cygwin's setup.exe.

(And add use warnings; after use strict; in your Perl scripts. This isn't related to your problem, but it's good practice.)

这篇关于无法在cygwin中执行系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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