【发布时间】:2021-03-07 19:07:59
【问题描述】:
所以我想传递的原始命令是 -
runuser -l chrome -c 'DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/yourcode" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=VastInstance'
我尝试了两种方法。第一个是-
def pcall(pram):
s.run([pram], shell=True)
pcall("runuser -l raiyan -c 'DISPLAY= /opt/google/chrome-remote-desktop/start-host --code=\"4/0AY0e-g6DezhppO-9eF6BCGahZOOxN-Rs2uG0lm-G0FRIL1PvLR22-oqnCBHGmVUjr86o2A\" --redirect-url=\"https://remotedesktop.google.com/_/oauthredirect\" --name=Raiyan\'s PC' --pin=000000") ```
where pcall is a function that calls subprocess.run() and the error says ```/bin/sh: 1: Syntext error: Unterminated quoted string.```
So i tried another way - ```s.run({'runuser','-l,'raiyan','-c','DISPLAY=','/opt/google/chrome-remote-desktop/start-host','--code=','4/SomeCode','--redirect-url=','https://remotedesktop.google.com/\_/oauthredirect','--name=','raiyan'])```
And this also show Syntex error right here
>https:// remotedesktop.google .com/\➡️_/⬅️oauthredirect
我完全不知道在这里做什么。 [而且我也不明白为什么代码标签在这里不起作用:( ]
【问题讨论】:
-
为什么不使用shlex?
-
老实说,我不知道这存在。 shlex 是否比 subprocess 更高效?
-
shlex不会运行任何东西,但它会像 shell 一样拆分您的命令,以便您可以将其传递给subprocess.run。你可以用shlex.split("""runuser -l ....""")试试看,它把它分成5个参数,而你把它分成12个(导致它失败)
标签: python linux subprocess