【发布时间】:2025-12-22 02:45:14
【问题描述】:
在 Ubuntu 中,我使用subprocess.Popen 调用一个可执行文件,它将一些输出文件保存在服务器(Picloud)的硬盘上。该代码已在本地 Ubuntu 机器上成功测试。但是,它在服务器上不起作用。我的方法如下:
#create a new folder.
#The permission is drwxrwx--- both locally and on the server end
os.makedirs(folder)
#copy the executable file to this folder.
#The permission is drwxrwx--- both locally and on the server end after copy
shutil.copy("a.exe", folder)
#call this exe file.
#The permission is drwxrwx--- locally but changed to drwxr-x--- on the server end.
#Since I do not have the write permit, my code fails
subprocess.Popen("a.exe")
>>>OSError: [errno 13] permission denied.
我不确定为什么 subprocess 会更改我在服务器端的文件夹权限。所以我尝试使用sudo 模式作为:
subprocess.Popen("sudo", "a.exe")
正如我所料,此代码仅在本地工作。
那么任何人都可以帮我解释为什么 subprocess 会删除我的写权限吗?
谢谢!
【问题讨论】:
标签: python windows amazon-ec2 subprocess administrator