使用子进程从数组调用命令?
Calling command from array with subprocess?
我有以下代码:
'''
Created by Baran Skistad, bjskistad on GitHub.
Please give credit to Baran Skistad if you use this.
'''
index = 0
file = 'example.shs'
data = ''
loop = 0
loopString = ''
commands = ['']
command = 0
done = False
import subprocess
with open(file, 'r') as myfile:
data = myfile.read().replace('\n', '')
commands = [part + ';' for part in data[:-1].split(';')]
print commands
if done:
while command <= len(commands):
ccommand = commands[command]
print ccommand[command][3:len(ccommand[command]-1)]
subprocess.call([ccommand[3:len(commands[command]-1)]])
command = command + 1
它给我以下错误:
File "/home/ubuntu/workspace/source.py", line 23
print ccommand[command][3:len(ccommand[command]-1)]
^
SyntaxError: invalid syntax
Process exited with code: 1
example.shs
文件如下所示:
run rm wha;
run git clone https://github.com/jel-lang/jel.git;
如你所见,这是我制作的自定义语言。我想让 Python 文件做的是从列表中的每个项目中取出前 4 个字母和最后一个字母,然后使用 subprocess
.
运行 它
那是python2代码,你是运行它用python3.运行它用命令python2
你就赢了'解决不了这个问题。
我有以下代码:
'''
Created by Baran Skistad, bjskistad on GitHub.
Please give credit to Baran Skistad if you use this.
'''
index = 0
file = 'example.shs'
data = ''
loop = 0
loopString = ''
commands = ['']
command = 0
done = False
import subprocess
with open(file, 'r') as myfile:
data = myfile.read().replace('\n', '')
commands = [part + ';' for part in data[:-1].split(';')]
print commands
if done:
while command <= len(commands):
ccommand = commands[command]
print ccommand[command][3:len(ccommand[command]-1)]
subprocess.call([ccommand[3:len(commands[command]-1)]])
command = command + 1
它给我以下错误:
File "/home/ubuntu/workspace/source.py", line 23
print ccommand[command][3:len(ccommand[command]-1)]
^
SyntaxError: invalid syntax
Process exited with code: 1
example.shs
文件如下所示:
run rm wha;
run git clone https://github.com/jel-lang/jel.git;
如你所见,这是我制作的自定义语言。我想让 Python 文件做的是从列表中的每个项目中取出前 4 个字母和最后一个字母,然后使用 subprocess
.
那是python2代码,你是运行它用python3.运行它用命令python2
你就赢了'解决不了这个问题。