Page 1 sur 1

backslash dans command run

Posté : 13 sept. 2016 - 12:27
par MairieDeChallans
Bonjour,

j'essaye de lancer une commande run dans le fichier pyton.py mais à chaque fois mes backslash sont doublés et du coup la commande échoue.
Toujours le même problème, c:\ est interprêté en c:\\.

La commande a exécuter est :

Code : Tout sélectionner

powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\

Code : Tout sélectionner

run(r'powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\')

Code : Tout sélectionner

run(r'"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"')
ou

Code : Tout sélectionner

commandsm=r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"
run(commandsm)
Toutes ces commandes me renvoient :

Code : Tout sélectionner

2016-09-13 11:58:29,858 CRITICAL Fatal error in install script: CalledProcessError: Command '('"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\\ -verbose"',)' returned non-zero exit status 1:Traceback (most recent call last):
  File "C:\wapt\common.py", line 3166, in install_wapt
    exitstatus = setup.install()
  File "c:\users\adminv~1\appdata\local\temp\waptxfvtxf\setup.py", line 71, in install
    run(r'"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\ -verbose"')
  File "C:\wapt\common.py", line 3013, in run
    return setuphelpers.run(*arg,pidlist=self.pidlist,**args)
  File "C:\wapt\setuphelpers.py", line 602, in run
    raise subprocess.CalledProcessError(proc.returncode,cmd,''.join(output))
CalledProcessError: Command '('"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\\ -verbose"',)' returned non-zero exit status 1

2016-09-13 11:58:29,940 CRITICAL Package chal-config-pc not installed due to errors : CalledProcessError: Command '('"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\\ -verbose"',)' returned non-zero exit status 1
Comment faire pour garder intacte le "c:\" dans la commande run ?

Merci.

Re: backslash dans command run

Posté : 13 sept. 2016 - 16:01
par fludo67
Bonjour,

Avez vous essayé le caractère d'échappement \ ? ( c:\\)

Code : Tout sélectionner

commandsm=r'powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\\'

Re: backslash dans command run

Posté : 16 sept. 2016 - 11:09
par MairieDeChallans
Bonjour,

oui, et du coup cela donne c:////
(tout les backslashs sont doublés)
:twisted:

Re: backslash dans command run

Posté : 19 sept. 2016 - 09:44
par Aedenth
Bonjour,

Je ne sais pas si c'est la meilleur façon de faire mais en utilisant le code suivant, cela devrait fonctionner.

Code : Tout sélectionner

command = r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath "
path = os.path.normpath('C:\\')
commandsm = ''.join([command,path])
run(commandsm)

Re: backslash dans command run

Posté : 19 sept. 2016 - 15:24
par MairieDeChallans
Merci cette solution fonctionne !