我可以在 Perl 的反引号中执行多行命令吗? [英] Can I execute a multiline command in Perl's backticks?

查看:27
本文介绍了我可以在 Perl 的反引号中执行多行命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Unix 中,我有一个要使用 nohup 运行的进程.但是,此过程将在某个时候等待提示,我必须输入 yesno 才能继续.到目前为止,在 Unix 中我一直在做以下事情

In Unix, I have a process that I want to run using nohup. However this process will at some point wait at a prompt where I have to enter yes or no for it to continue. So far, in Unix I have been doing the following

nohup myprocess <<EOF
y
EOF

所以我使用 nohup 启动进程 'myprocess',并在一个带有 'y' 的文件中使用管道,然后关闭该文件.上面的几行实际上是三个单独的命令 - 即我在 UNIX 的第一行按 Enter,然后我得到一个提示,我输入y",然后按 Enter,最后输入EOF"并再次按回车.

So I start the process 'myprocess' using nohup and pipe in a file with 'y' then close the file. The lines above are effectively three seperate commands - i.e. I hit enter on the first line in UNIX, then I get a prompt where I enter 'y' and then press enter to then finally type 'EOF' and hit return again.

我想知道在 Perl 中执行此命令,但我不确定如何执行此命令,因为它超过三行.我不知道以下是否有效....

I want to know execute this in Perl but I am not sure how I can execute this command as it is over three lines. I don't know if the following will work....

my $startprocess = `nohup myprocess <<EOF &
y
EOF
`

请帮忙 - 谢谢!

推荐答案

我认为您的建议会按原样进行.如果没有,请尝试用管道替换重定向:

I think your proposal will work as is. If not, try replacing the redirect with a pipe:

my $startprocess = `(echo "y" | nohup myprocess) &`;

此外,根据您为什么要执行 nohup,请查看以下使用 Proc::Daemon 的纯 Perl 守护程序方法:如何在 linux 中将 Perl 脚本作为系统守护进程运行?

Also, depending on WHY you are doing a nohup, please look at the following pure Perl daemonizing approach using Proc::Daemon : How can I run a Perl script as a system daemon in linux?

这篇关于我可以在 Perl 的反引号中执行多行命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆