通过Python System/SubProcess CMD,在执行脚本中获取变量

发布于 2025-02-09 01:01:59 字数 450 浏览 0 评论 0原文

我正在尝试在使用Python System()执行的Shell脚本中获得变量的值集。但是,我不知道如何执行OS.System()调用后如何获取该值。是否可以使用Python子过程命令获取它。

cmd = "script.sh --input1 "+ inputValue1 + " --input2 '"+ inputValue2 + "' --output-file " + pathToOutputFile
os.system(cmd)

执行执行某些函数时,执行过程中的脚本sh会设置一个本地变量。我想执行该变量的值post os.system()。是否将另一个参数传递给脚本并在system()完成时将其设置为脚本中的值并使用该值 - 是否可以使用python中的os.system()或subprocess()?

请帮助您使用可以在Python中获取可变值的任何代码段。

感谢您的指示。

I am trying to get a variable's value set inside shell script executed using python system(). HOwever I dont have idea how to fetch that value after os.system() call is executed. whether it can be fetched using the python subprocess command.

cmd = "script.sh --input1 "+ inputValue1 + " --input2 '"+ inputValue2 + "' --output-file " + pathToOutputFile
os.system(cmd)

The script.sh during execution sets one local variable when executing some function. I want to fetch that variable's value post os.system() is executed. Whether passing another argument to script and getting that value set inside script and use that value when system() is completed - is it possible using os.system() or subprocess() in python?

please help with any code snippet that can get the variable value in python.

thanks for your pointers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文