读取未知选项

2024-09-21 05:52:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python脚本执行shell命令。这是命令:

ntpservlist=( $OMC_NTPSERV ) && IFS=',' read -ra ntplist <<< "$ntpservlist" &&  for i in "${ntplist[@]}" ; do echo "server $i" >> /etc/inet/ntp.conf ; done

使用脚本执行命令时,会出现以下错误:

^{pr2}$

但是如果我使用命令行执行同一个命令,它会正确执行而不会出现任何错误。在

我用的是:

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    (out, err) = proc.communicate()

执行命令。在


Tags: 命令脚本read错误procshell执行命令ra
1条回答
网友
1楼 · 发布于 2024-09-21 05:52:59

您的交互式shell是bash,但是{}使用的系统shell是ksh的风格。要使用bash,请使用executable选项:

proc = subprocess.Popen(command,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE,
                        shell=True,
                        executable="/bin/bash") # or whatever the right path is
(out, err) = proc.communicate()

大多数命令似乎是有效的ksh,但一个区别是,read -A,而不是{},用于填充数组。在

相关问题 更多 >

    热门问题