【问题标题】:Run the shell commands in Perl using system() function in Windows在 Windows 中使用 system() 函数在 Perl 中运行 shell 命令
【发布时间】:2013-07-13 01:00:35
【问题描述】:

我正在将一些插件从 Linux 迁移到 Windows

插件是使用Perl 编写的,它有一个名为system() 的函数,可以执行shell 命令。

但我现在正在迁移到 Windows。有什么方法可以在 windows 中使用 system() Per 函数运行 linux 命令?

一些Perl Module 对此有用吗?

【问题讨论】:

    标签: windows perl shell


    【解决方案1】:

    您可以运行system() 命令,但有一些注意事项。 Using system or exec safely on Windows 中有一个很好的描述。本文产生了Win32::ShellQuote 模块。

    【讨论】:

    • 问题是 awk 不适用于 system。这是一个shell命令,Windows不会理解。
    • 哎哟。您可能想尝试安装 Cygwin 并从那里运行您的 perl 脚本。
    • @YatinSaraiya 他正在尝试将一些插件从 Linux 迁移到 Windows
    • 是的。 Cygwin (cygwin.org) 是 UNIX 到 Windows 的“端口”。它带有 bash。可以选择安装perl、awk/gawk等,那么port应该比较简单。
    【解决方案2】:

    您想在 windows shell 中运行 linux 命令 vie Perl?如果是这样,请尝试使用 Cygwin (www.cygwin.com) 之类的 Linux 环境。否则,您还必须迁移系统调用。

    【讨论】:

    • 问题是awk 无法与系统一起使用。这是一个shell命令,Windows不会理解。它没有运行任何像 Cygwin 这样的 windows unix 转换器。它是其他系统读取的插件。那个时候仍然是Windows。用perl我们可以做点什么吗?
    • 您能提供一个代码示例吗?看来我到目前为止还没有得到它......;)
    • system(awk '{ if($9 == "t4") print $0;}' myfile.txt )
    • system(bash -i -c 'your script')?
    • Error o/p ... 错误:'bash' 未被识别为内部或外部命令,
    猜你喜欢
    • 2013-04-16
    • 2015-11-02
    • 1970-01-01
    • 2020-04-08
    • 2011-07-14
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 2013-01-31
    相关资源
    最近更新 更多