免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3703 | 回复: 4
打印 上一主题 下一主题

求助一个脚本问题:如何在perl脚本中执行一个程序或bat脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-20 11:10 |只看该作者 |倒序浏览
本帖最后由 下一秒 于 2010-07-20 12:01 编辑

公司安排一个测试任务,这个脚本我不懂哦。大侠帮忙给写一个详细的,最好有说明如何用。PERL一窍不通啊,帮忙啊
windows平台环境。
脚本1:模拟启动一个c:\WINDOWS\NOTEPAD.EXE   

#!perl
BEGIN { require $ENV{'LKROOT'}.'/etc/default/LifeKeeper.pl'; }

use LK;
use POSIX;
use Getopt::Std; # use the standard getopt package

$LKROOT=$ENV{'LKROOT'};
$ResType="app";
$AppType="gen";
$CMD=`basename $0`;
chomp $CMD;

sub parseOptions { # noparams

        getopts('t:i:');
        $tag = "$opt_t";
        $id = "$opt_i";
};
# Perform commands that restore the protected application to service.
# HINT: To fork a new process you can use the LifeKeeper supplied start command
# located at $LKROOT/bin/start.exe and executable in perl as illustrated here.
# For example, to start the Microsoft Notepad accessory as follows:
# system("start", "$ENV{'SystemRoot'}/notepad.exe", "$ENV{'LKROOT'}/TMP/YourFileName.txt");

# -------------------------------------------------------------------------------------
#                     Custom code goes here
# -------------------------------------------------------------------------------------

# RetCode is used to identify a successful or failed restore
$RetCode = $?>>8; # In perl, the application return code is offset 8 bits.
if ( $RetCode != 0 )
{
        # Log failed restore and return failed.
        `$ENV{'LKROOT'}/bin/lk_err -c FRS_ERR -n 27455 -d TO_STDERR -p $CMD "LifeKeeper: AppKit RESTORE; The \\"$tag\\" resource failed to start properly.  Return code was \\"$RetCode\\".  Restore has FAILED."`;
        exit $RetCode;
}

# Return success
exit 0;


脚本2:停止NOTEPAD.EXE进程脚本
#!perl
BEGIN { require $ENV{'LKROOT'}.'/etc/default/LifeKeeper.pl'; }

use LK;
use POSIX;
use Getopt::Std; # use the standard getopt package

$LKROOT=$ENV{'LKROOT'};
$ResType="app";
$AppType="gen";
$CMD=`basename $0`;
chomp $CMD;

sub parseOptions { # noparams

        getopts('t:i:');
        $tag = "$opt_t";
        $id = "$opt_i";
};
# Perform commands that remove the protected application from service.

# -------------------------------------------------------------------------------------
#                     Custom code goes here
# -------------------------------------------------------------------------------------

# RetCode is used to identify successful or failed remove
$RetCode = $?>>8; # In perl, the application return code is offset 8 bits.
if ( $RetCode != 0 )
{
        # Log failed remove operation and return.
        `$ENV{'LKROOT'}/bin/lk_err -c FRS_ERR -n 27855 -d TO_STDERR -p $CMD "LifeKeeper: AppKit REMOVE; The \\"$tag\\" resource failed to stop properly.  Return code was \\"$RetCode\\".  Remove has FAILED."`;
        exit $RetCode;
}

# Return success.
exit 0;

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
2 [报告]
发表于 2010-07-20 11:21 |只看该作者
代码中有
`$ENV{'LKROOT'}/bin/lk_err -c FRS_ERR -n 27455 -d TO_STDERR -p $CMD "LifeKeeper: AppKit RESTORE; The \\"$tag\\" resource failed to start properly.  Return code was \\"$RetCode\\".  Restore has FAILED."`;

论坛徽章:
0
3 [报告]
发表于 2010-07-20 11:57 |只看该作者
本帖最后由 下一秒 于 2010-07-20 12:01 编辑

都是什么意思啊?有两个脚本的。

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
4 [报告]
发表于 2010-07-20 12:03 |只看该作者
如何在perl脚本中执行一个程序或bat脚本

用 `` 或者 system()

详细的最好找个perl文档翻翻

论坛徽章:
0
5 [报告]
发表于 2010-07-20 12:52 |只看该作者
还是不懂啊,大哥能不能给做个model
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP