嗨,我试图运行一个bash脚本使用python,但我得到一个权限错误,当我试图用python运行它



长话短说,我使用python和bash,所以我可以只运行一个python文件和我所有的docker容器和自制脚本可以运行,但每次我试图运行一个bash脚本,我得到权限13 (bare mind我确实使用chmod u+x命令)

下面是代码:
import os
from colorama import Fore
import time
import subprocess
while True:
print(Fore.GREEN + "Welcomen")
print("To Automater")
options = print(Fore.WHITE + """what would you like to do?n1.Start Containersn2.Stop Containersn3.Run A scriptn4.Add containersn5.Exitn""")
started = input("1-4:n")
if started == "1":
print(Fore.RED + "Starting containers")
#os.startfile(Start_Containers.sh)
subprocess.call(["./Start_Containers.sh"])

,这里是我得到的错误:

PermissionError: [Errno 13] Permission denied: './Start_Containers.sh'
Process finished with exit code 1

下面是所有代码:

import os
from colorama import Fore
import time
import subprocess
while True:
print(Fore.GREEN + "Welcomen")
print("To Automater")
options = print(Fore.WHITE + """what would you like to do?n1.Start Containersn2.Stop Containersn3.Run A scriptn4.Add containersn5.Exitn""")
started = input("1-4:n")
if started == "1":
print(Fore.RED + "Starting containers")
#os.startfile(Start_Containers.sh)
subprocess.call(["./Start_Containers.sh"])
if started == "2":
print(Fore.RED + "Stoping containers")
os.startfile("./Stop_Containers.sh")
elif started == "3":
Scripts = []
for files in os.listdir():
Scripts.append(files)
print(Scripts)
elif started =="4":
while True:
add_container = input("Would you like to add a container [y/N]")
if add_container.upper() == "Y":
print("Ok Lets add some")
added_containers = input("ok lets add a container")
elif add_container.upper() == "N":
break
exit()
elif started == "5":
print(Fore.GREEN + "Thank you for using Automater")
time.sleep(1)
break
exit()

要运行bash脚本,看起来需要管理员权限。在linux上使用sudo python <script_name>.py运行脚本,而不是使用python <script_name>.py运行脚本。

严格地说,这是一个非常非常糟糕的做法。但如果你这样做只是为了好玩(看起来是这样),那也没关系。但是千万不要在任何重要的事情上这样做。

相关内容

  • 没有找到相关文章

最新更新