`read` 命令导致分叉进程在前台发生
`read` command causes forked process to happen in foreground
您好,我正在尝试编写 bash 脚本以在后台启动 QEMU 并等待用户按下某个键以继续执行脚本。
这是我目前拥有的:
setup_for_greengrass # these are functions
run_qemu & # fork function and try to run in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass
但是,我在终端中得到的是 QEMU 控制台,我无法继续执行脚本。如果我 fork 进程并且那里没有 read
命令,它会按预期工作并且 QEMU 控制台不会显示并且脚本继续前进。
关于如何以不同方式分叉 QEMU 进程或等待用户输入有什么建议吗?
我想通了...在 bash 版本 4 或更高版本中,zsh 支持这个名为 coproc
.
的命令
https://www.geeksforgeeks.org/coproc-command-in-linux-with-examples/
https://www.zsh.org/mla/users/2011/msg00095.html
所以编写如下脚本,它应该在后台启动 qemu,让脚本继续运行。
#!/bin/zsh # Make sure to use zsh or upgrade your version of bash
setup_for_greengrass
coproc run_qemu # launch qemu in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass
您好,我正在尝试编写 bash 脚本以在后台启动 QEMU 并等待用户按下某个键以继续执行脚本。
这是我目前拥有的:
setup_for_greengrass # these are functions
run_qemu & # fork function and try to run in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass
但是,我在终端中得到的是 QEMU 控制台,我无法继续执行脚本。如果我 fork 进程并且那里没有 read
命令,它会按预期工作并且 QEMU 控制台不会显示并且脚本继续前进。
关于如何以不同方式分叉 QEMU 进程或等待用户输入有什么建议吗?
我想通了...在 bash 版本 4 或更高版本中,zsh 支持这个名为 coproc
.
https://www.geeksforgeeks.org/coproc-command-in-linux-with-examples/
https://www.zsh.org/mla/users/2011/msg00095.html
所以编写如下脚本,它应该在后台启动 qemu,让脚本继续运行。
#!/bin/zsh # Make sure to use zsh or upgrade your version of bash
setup_for_greengrass
coproc run_qemu # launch qemu in the background
echo "Press anything to continue once VM is finished booting...\n"
read fullname # wait for user to press a key
install_greengrass