简体   繁体   English

通过Cygwin通过“ Windows命令”启动Perl脚本

[英]Start Perl script via “Windows Command” through Cygwin

i have the following issue: 我有以下问题:

I try to start a perl script from the windows scheduler through cygwin 我尝试通过cygwin从Windows Scheduler启动Perl脚本

Steps i do: Call process.bat file In the process.bat i call bash with the parameter for the perl script 我要做的步骤:调用process.bat文件在process.bat中,我使用perl脚本的参数调用bash

Symptoms: If i call "perl scriptpath" directly from cygwin it works like a charm If i call the script from the windows cmd with bash it will not work. 症状:如果我直接从cygwin调用“ perl脚本路径”,则它就像一个符咒。如果我从Windows cmd中使用bash调用该脚本,它将无法正常工作。

Command: C:\\cygwin\\bin\\bash.exe --login /cygdrive/c/scripts/testscript.pl It prints the following: 命令:C:\\ cygwin \\ bin \\ bash.exe --login /cygdrive/c/scripts/testscript.pl它显示以下内容:

Line 3: use: command not found
Line 4: use: command not found
Can't find file Test

Script: 脚本:

#!/usr/bin/perl

use strict;
use warnings;
print "Test";

Probably i'm making only a small mistake and cannot see it. 可能我只是犯了一个小错误,看不到它。 It seems to interpret it with the windows cmd instead of the perl. 似乎用Windows cmd而不是perl来解释它。

The parameter passed to bash will be treated as a Bash script, not a Perl script. 传递给bash的参数将被视为Bash脚本,而不是Perl脚本。 There is no reason to use Bash in this case - just invoke Perl directly: 在这种情况下,没有理由使用Bash-只需直接调用Perl:

C:\cygwin\bin\perl.exe /cygdrive/c/scripts/testscript.pl

If you really want to do it your way - calling a cmd script which calls a Bash script which calls a Perl script - then you would need to write a Bash script to invoke your Perl script: 如果您真的想按自己的方式做-调用一个cmd脚本,一个Bash脚本,一个Perl脚本,则您需要编写一个Bash脚本来调用您的Perl脚本:

#!/bin/sh
/cygdrive/c/scripts/testscript.pl

And pass that Bash script as the parameter when you invoke bash. 并在调用bash时将该Bash脚本作为参数传递。

You might like to use option -c to have bash execute a command, like this: 您可能希望使用选项-c来让bash执行命令,如下所示:

C:\cygwin\bin\bash.exe --login -c /cygdrive/c/scripts/testscript.pl 

From the bash 's man-page: bash的手册页中:

-c string -c字符串

If the -c option is present, then commands are read from string. 如果存在-c选项,则从字符串读取命令。 If there are arguments after the string, they are assigned to the positional parameters, starting with $0. 如果字符串后面有参数,则将它们分配给位置参数,从$ 0开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM