2014-04-14 4 views
1

"파이썬 submit.py 경로/arg"를 실행하려고하면 파일을 스캔 한 후 명령에 삽입하는 프로그램을 작성하려고합니다. 오류. 나는 당신의 호출에 의해 혼란 스러워요python 코드에서 args를 사용하여 python을 실행하는 방법

#!/usr/bin/python 
import os 
import glob 
import subprocess 
import commands 
import time 
import threading 

exe = [] 
os.chdir("/home/malwares") 
exe = glob.glob('*.exe') 
exe1 = ''.join(exe) 
exe1 = exe1.replace("']", "") 
exe1 = exe1.replace("['", "") 
os.chdir("/home/utils/") 

//here i tried to run python script with args 
subprocess.call(["python", "submit.py", "/home/malwares",exe1]) 
+5

무엇이 오류입니까? – heinst

+1

왜 파이썬 스크립트에 대한 하위 프로세스를 호출합니까? 왜 그것을 가져 오지 않고 직접 함수를 호출할까요? – njzk2

+0

1. 무엇을 의미합니까? 5. 오류는 중요하지 않습니다. 아마도 사용하는 기능이 맞지 않을 것입니다. – user3532344

답변

1

: 내가 성공하지 많은 명령을 시도 (os.system을, 일은 os.popen, subprocess.call, 간부) 사전에 덕분에

이 내 프로그램입니다 str.replace. 왜 [']이라는 파일 이름을 가지고 있습니까? 하지만 알았어, 당연하지, 적어도 그렇게하자. ...

os.chdir('/home/malwares') 
exe = glob.glob('*.exe') # no need to initialize this first. 
exe_str = ''.join(exe) # name it a little more descriptively than exe1 
trans_table = str.maketrans('', '', "[']") 
exe_str = exe_str.translate(trans_table) 
# this is probably faster than 
# ''.join([filename.translate(trans_table) for filename in glob.glob('*.exe')]) 
# but you may want to profile it 

subprocess.call(['python', 'submit.py', '/home/malwares', exe_str]) 
# is this REALLY what you want??? This will do: 
# >> python submit.py /home/malwares FILEONE.exeFILETWO.exeFILETHREE.exe 
# maybe you should have used ' '.join(exe) instead? 
+0

도움을 주셔서 감사합니다 다른 python 스크립트 (submit.py)로 파일을 실행하려면 – user3532344

+0

([ 'python', 'submit.py', '/ home/malwares /', exe_str] @ user3532344 네, 그 정도는 분명합니다. 단지 그만한 나머지 부분입니다. :) –

관련 문제