范例:
范例01:阻塞方式调用子进程执行命令
path:="D:\\Program Files\\Python\\Python38\\python.exe";
//创建管道
ret:= Sysexecnewpipe();
//创建成功,执行命令:获取python的版本号
If ret then handle:=SysExec(path, "py -V",nil, true,code,5000);
else return false;
return code;
//结果:
范例02:调用子进程执行TSL语言脚本
主程序代码:
path := "D:\\Program Files\\AnalyseNG.NET\\TSL.exe";
filepath := "D:\\test\\csv\\test.tsl";
//创建管道
ret := Sysexecnewpipe();
//创建成功,执行TSL语言脚本
If ret then handle := SysExec(path,"tsl "$filepath,nil,true,code,5000);
else return false;
return code;
test.tsl代码:
data := array((1,2,3),(4,5,6),(7,8,9));
ret := ExportFile(ftxls(),"","D:\\test\\csv\\test.xlsx",data);
//导出成功,返回码为1
if ret=1 then
begin
echo "ExportFile Success";
systerminate(1);
end else
begin
echo "ExportFile Fail:"$ret;
//导出成功,返回码为0
systerminate(0);
end
return;
//结果:
//导出文件内容:
范例03:非阻塞方式下执行命令并获取输出内容
path:="D:\\Program Files\\Python\\Python38\\python.exe";
//创建管道
ret:= Sysexecnewpipe();
//创建成功,执行命令:获取python的版本号
if ret then handle:=SysExec(path,"py -V",nil,false,code);
else return false;
//循环获取执行后的输出内容
t1:= "";
while t1="" do
begin
t1:= SysexecReadpipe(handle);
sleep(100);//等待100毫秒
end
SysTerminate(code, handle);//终止进程
return t1;
返回结果:
范例04:非阻塞模式下通过”in”与管道输入串
//创建读写管道
SysexecNewpipe(0);
path:="D:\\TinySoftNG\\AnalyseNG.NET\\TSL.exe";
//非阻塞执行,返回进程句柄,并输入命令a:="abc",'\r\n'表示回车功能
hand:= SysExec(path,"tsl",nil,array('wait':0,'in':'a:="abc"\r\n'),code);
//向SysExec进程所在管道写入内容
SysexecWritepipe(hand,"datetostr(20221130T)\r\n");
sleep(500); //等待'in'传入的命令执行完成
//向管道写入获取变量a的值
SysexecWritepipe(hand,"a\r\n");
//获取SysExec进程所在管道的输出内容
t1:= "";
while t1="" do
begin
t1:= SysexecReadpipe(hand);
sleep(100); //100毫秒读取一次
end
SysTerminate(code,hand);//终止进程
return t1;
返回:
