简体   繁体   English

shell 脚本如何从自身内部执行另一个 shell 脚本

[英]How does a shell script execute another shell script from within itself

My question is how does a shell script execute another shell script does it spawn in a new process?我的问题是一个 shell 脚本如何执行另一个 shell 脚本它是否在新进程中产生? or is it executed in the same process as the script that called it?还是在与调用它的脚本相同的进程中执行? A example would be a Python script that is executed from a shell script after a condition is met also how would someone write this shell script where it would spawn the Python script and then exit itself without killing the Python script一个例子是在满足条件后从 shell 脚本执行的 Python 脚本,还有人如何编写这个 shell 脚本,它会生成 Python 脚本,然后在不杀死 Python 脚本的情况下退出自己

Yes shell also will spawn new process if you invoke shell script within shell.是的,如果您在 shell 中调用 shell 脚本,shell 也会产生新进程。 if you want to spawn python script and exit without killing, run python in background in shell script/ or disown python process.如果您想生成 python 脚本并退出而不杀死,请在 shell script/ 或 disown python 进程中在后台运行 python。

Python can spawn new processes and control their lives. Python 可以产生新的进程并控制它们的生命。

You can create and manage them using modules such as subprocess : " The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. "您可以使用诸如subprocess 之类的模块来创建和管理它们:“ subprocess 模块允许您生成新进程,连接到它们的输入/输出/错误管道,并获取它们的返回代码。

If you want to run them on other threads, you can use multiprocessing : " multiprocessing is a package that supports spawning processes using an API similar to the threading module. "如果你想在其他线程上运行它们,你可以使用multiprocessing :“ multiprocessing 是一个包,它支持使用类似于线程模块的 API 生成进程。

Shell scripts are something different, maybe this question (and its answers) can help you understand shell scripts launching other scripts :) Shell 脚本有所不同,也许这个问题(及其答案)可以帮助您了解启动其他脚本的 Shell 脚本:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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