次のエラーが表示されます。
/bin/sh: 1: Syntax error: redirection unexpected
Traceback (most recent call last):
File "vpntest.py", line 24, in <module>
output = check_output(command, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'source /etc/openconnect/dsn-dsmc.conf; openconnect -b -u ${USER} --cafile=${CACERT} --certificate=${CERT} --sslkey=${KEY} ${HOST} <<< $PASS;ping 8.8.8.8 -w 5; ip addr; echo $?' returned non-zero exit status 2
これは私のコードです:
import subprocess
import argparse
import sys
from subprocess import check_output
def parse_args(argv):
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--user", action="store",
help="User for login",
dest="user")
parser.add_argument("-p", "--pwd", action="store",
help="Password",
dest="pwd")
args = parser.parse_args()
return args
args = parse_args(sys.argv[1:])
command = 'source /etc/openconnect/cfgfile.conf; openconnect -b -u ${USER} --cafile=${CACERT} --certificate=${CERT} --sslkey=${KEY} ${HOST} <<< $PASS;ping 8.8.8.8 -w 5; ip addr; echo $?'
output = check_output(command, shell=True)
私は変更しようとしました:
command = 'source /etc/openconnect/cfgfile.conf; openconnect -b -u ${USER} --cafile=${CACERT} --certificate=${CERT} --sslkey=${KEY} ${HOST} <<< $PASS;ping 8.8.8.8 -w 5; ip addr; echo $?'
為に
command = '#!/bin/bash source /etc/openconnect/cfgfile.conf; openconnect -b -u ${USER} --cafile=${CACERT} --certificate=${CERT} --sslkey=${KEY} ${HOST} <<< $PASS;ping 8.8.8.8 -w 5; ip addr; echo $?'
しかし、コマンドまたは出力を印刷しようとすると、結果は表示されず、スペースだけが表示されます。