转:PERL实例精解(第4版) -Win32进程创建

本文深入探讨了如何使用Perl在Win32环境下创建应用程序进程,详细讲解了system函数的用法,并针对可能出现的警告信息和输出管理提供了实用技巧。
摘要由CSDN通过智能技术生成
 
文章来自:http://book.chinaunix.net/showart.php?id=1525
18.2.9 Win32进程创建

18.2.9 Win32进程创建

在Win32系统上,读者也可以像在UNIX系统上一样使用system函数、exec函数和反引号。

start命令。 Windows和UNIX都使用system函数启动操作系统命令。system负责执行程序,并在程序完成之前不返回。如果将Windows start命令作为参数提供给Perl的system函数,便会运行新的应用程序,同时脚本仍将继续执行。

示例18.54

use warnings;
1 $return_value = system ("start /Program
Files/Netscape/Communicator/Program/netscape.exe");
2 print "Program continues; Netscape is running./n";
3 print "The return_value from system is $return_value./n";
(Output)
Program continues; Netscape is running.
The return_value from system is 0.

解释

1. Perl的system函数启动新的进程。通过使用Win32 start命令,可以启动新的进程。与此同时,Perl脚本还将继续运行,而不是等待新进程执行完毕。如果进程启动成功,system函数将返回0。

2. Netscape Communicator已经启动,并将继续运行,直到关闭所有窗口。

3. 打印system函数的返回值。

Win32::Spawn模块。 Win32::Spawn函数的行为类似于system函数和Windows start菜单。

格式

use Win32;
Win32::Spawn($ProgramName, $CommandLine,$ProcessID);
示例18.55
1 use warnings;
2 use Win32;
3 $|=1;
4 $Application="C:/mksnt/date.exe";
5 $CommandLine="date +%D";
6 $status=Win32::Spawn($Application, $CommandLine, $ProcessID);
7 if ($status != 0){
8 print "pid is $ProcessID./n";
}
else{
9 print "Didn't spawn $Application./n";
10 print Win32::FormatMessage(Win32::GetLastError);
}
(Output)
8 pid is 448.
11/01/00

解释

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值