简体   繁体   English

退出python程序后调用bash脚本

[英]Call bash script after exiting python program

I'm new to Python and have been able to find answers to most of my questions here so I thought you guys could help me with this one: 我是Python的新手,已经能够在这里找到大多数问题的答案,所以我认为你们可以帮助我解决这个问题:

I'm developing somewhat of a hybrid application using bash scripts to show menus and to call python applications (I'm doing it this way to simplify things). 我正在使用bash脚本开发一个混合应用程序,以显示菜单并调用python应用程序(我这样做是为了简化事情)。

My problem is that when I end the python application, it simply terminates the process and to go back to the menus, I have to start the whole program again. 我的问题是,当我结束python应用程序时,它只是终止了进程并返回菜单,我必须再次启动整个程序。 I tried using "subprocess.call('xxx')" but it opens the bash scrips inside of the application I am running and shows text (echo) only, no other functions. 我尝试使用“ subprocess.call('xxx')”,但它会在我正在运行的应用程序内部打开bash脚本,并仅显示文本(回声),没有其他功能。

Is there a way to end the python application first and then call the shell script? 有没有一种方法可以先结束python应用程序,然后再调用shell脚本?

You can wrap your code in a while-true loop 您可以将代码包装在while-true循环中

while :; do
    # Assuming you want to show the menu before you start a program:
    bash showMenu.py
    python myScript.py
    # When the above scripts exits the process will start all over again
    # You might want to consider checking the exit code and only continue if the program exits with status code 0
    # [ $? gt 0 ] && break
done

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

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