Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

perl - macos shell script not returning control

I'm running a Perl script on High Sierra which calls a bash shell script using the 'system' command, but it is not returning control back to the Perl script.

@sysCmd=('~/bin/2mp3.1.sh');
system(@sysCmd) == 0 || die "system command failed: $?
";

My understanding of 'system' is that unlike 'exec', it is supposed to return back to the calling script. The bash script:

for i in *.flac ; do
    ~/bin/ffmpeg -i "$i" -acodec libmp3lame "$(basename "${i/.flac}")".mp3
    sleep 1
done

Once that is finished, the Perl script should pick up where it left off and continue, but no joy. Would appreciate some ideas please. I'm wearing asbesto pants just in case :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Find the tty of the perl command running the script and then execute:

tty=ttyOfPerlCommandRunningYourScript
while [ 1 ]; do
   clear
   date
   ps -ft $tty
   sleep 1
done

If the tty of the perl script is something like /dev/ttys010, then set tty=ttys010.

Since the child shell script is globbing its files, then you can execute ls *.flac | nl -ba and find the position of the file currently executed by ffmpeg to get an estimate for how much longer the shell script will continue running.

You can press control-C to terminate the above while loop. You can also use the up and down arrow keys to cycle through your command history to restart that loop.

At any iteration of the above while loop you should see the child bash command and any of its children. If the child ffmpeg command is currently executing, then the filename on that command line represents the current file being processed. Search the ls command's output to see where you are in the current progress.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...