【问题标题】:Subprocess change folder permission on Picloud (an AMAZON EC2 server)?Picloud(AMAZON EC2服务器)上的子进程更改文件夹权限?
【发布时间】: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


    【解决方案1】:

    在windows中,你可以用命令运行它:

    subprocess.Popen("runas /user:Admin a.exe")
    

    【讨论】:

    • 这适用于 Windows 吗?因为至少在 Linux 上,subprocess.Popen 的第一个参数需要是一个列表......
    • 没有在 Windows 上测试过。该代码在本地 ubuntu 机器上工作,但是相同的代码在服务器端失败。