Bonjour,
Etrange comportement de subprocess.Popen
Démonstration, je lance un appli graphique à partir de la console, je suis dans: "/home/vincent/PaQager"
Le code doit appeler un process non python qui exige un répertoire courant précis et différent de celui de l'appli. Chose très courante, en fait.~/PaQager$ python paqager.py
Le code:
Retours:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 old_rep = os.getcwd() os.chdir(folder) cmd = ["dh_make", "-c", "gpl3", "-s"] print "Folder exist: ", folder, os.path.isdir(folder) print "Command: ", cmd, "\n" try: mk = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE).communicate() for r in mk[0].split("\n"): print " ", r except OSError, why: print "Error :", why print "Done :" os.chdir(old_rep)
J'ai toujours utiliser 'os.chdir(dir)' dans ces cas là, c'est bien la première fois que subprocess ne le prend pas en compte.Folder exist: /home/vincent/PaQager/examples/oqapy-0.4.0/oqapy-0.4.0 True
Command: ['dh_make', '-c', 'gpl3', '-s']
For dh_make to find the package name and version, the current directory
needs to be in the format of <package>-<version>. Alternatively use the
-p flag using the format <name>_<version> to override it.
I cannot understand the directory name or you have an invalid directory name!
Your current directory is /home/vincent/PaQager, perhaps you could try going to
directory where the sources are?
Please note that this change is necessary ONLY during the initial
Debianization with dh_make. When building the package, dpkg-source
will gracefully handle almost any upstream tarball.
Done :
Dans le code il n'y a aucune utilisation de 'dh_make' qui aurait put laisser penser à une variable fixée avant.
J'ai tester 'os.system("cd %s" % folder)' à la place de 'os.chdir(dir)', sans succès.
Autre exemple:
est refusé, manifestement la commande "cd" ne passe pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 cmd = ["cd", folder, ";", "dh_make", "-c", "gpl3", "-s"] ou cmd = ["cd %s;" % folder, "dh_make", "-c", "gpl3", "-s"]
Y compris en mettant le chemin en clair.File "/usr/lib/python2.6/subprocess.py", line 480, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
raise child_exception
OSError: [Errno 2] Aucun fichier ou dossier de ce type
C'est grave, docteur?
Partager