简体   繁体   中英

How can I run and end the script() linux command from Perl?

#!/usr/bin/perl
$sim = "multiq";
`make SCHED=$sim`;
`script > scripter`;
`echo hi`;
print pack("c", 04);
~

This script hangs when script is called. Not sure how to get the perl script to keep running.

Note that backticks ( '' ) run a command and return its output. If you're going to ignore the output, use system as in

system("make SCHED=$sim") == 0 or die "$0: make exited " . ($? >> 8)

If you want to fire-and-forget a program (that is, start it in the background without worrying about when it completes), you can use

system("script >scripter &");

You're have to run that all in one child process if you want it to all interact. See the perlipc for various ways to handle that.

您可能需要查看Expect来控制交互式会话

backticks ('') run a command and return its output.So you can store and manipulate it further. If you want to ignore the output, use system(). Also if you want to run any process in background use & in the prefix of the process. For example you wish to start Gimp using your script simply say

system("gimp &");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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