1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
# code de battant
def runcommand (command) :
"""
code extrait de :
https://docs.python.org/3.5/library/subprocess.html
http://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line """
output = ""
try :
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
outputbyte = proc.stdout.read()
output = outputbyte.decode()
except UnicodeEncodeError :
print ("Une erreur et survenue lors de la conversion de byte à string",sys.stderr())
traceback.print_exc(file=sys.stderr) # ligne issus de : https://docs.python.org/3.5/library/traceback.html
finally :
return output
output1 = runcommand("cat tab_carractère_spéciaux.csv | cut -f1 | grep \"\.\"")
chaine = self.test = test
for j in chaine
if j = ""
output1 = runcommand(grep \"\.\"")
else
output1 = runcommand ("grep \"{0}\"").format(j)
if output1 != "" :
if output1 == (".") :
# resultat attendu : le programme devrait passer ici lorsquu'il trouve un point dans la ligne de commande
output2 = runcommand("grep \"{0}\" myfile".format("\."))
elif output1 != "" :
le programme semble paser ici quand il rencontre un point dans la ligne de command
output2 = runcommand("grep \"{0}\" myfile".format(output1))
chaine += output2
else
chaine += j |
Partager