Pagina 1 di 1

barra rovesciata nell'esecuzione del comando

Pubblicato: 13 settembre 2016 - 12:27
presso il Municipio di Challans
Buongiorno,

Sto provando a eseguire un comando nel file pyton.py, ma ogni volta le barre rovesciate vengono raddoppiate e il comando fallisce.
Il problema persiste, c:\ viene interpretato come c:\\.

Il comando da eseguire è:

Codice: Seleziona tutto

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

Codice: Seleziona tutto

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

Codice: Seleziona tutto

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

Codice: Seleziona tutto

commandsm=r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"
run(commandsm)
Tutti questi comandi mi restituiscono quanto segue:

Codice: Seleziona tutto

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
Come posso mantenere intatto il carattere "c:\" nel comando run?

GRAZIE.

Re: Barra rovesciata nell'esecuzione del comando

Pubblicato: 13 settembre 2016 - 16:01
di fludo67
Buongiorno,

Hai provato a usare il carattere di escape \? (c:\\)

Codice: Seleziona tutto

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

Re: Barra rovesciata nell'esecuzione del comando

Pubblicato: 16 settembre 2016 - 11:09
presso il Municipio di Challans
Ciao,

sì, e quindi appare così: c:////
(tutte le barre rovesciate sono raddoppiate)
:contorto:

Re: Barra rovesciata nell'esecuzione del comando

Pubblicato: 19 settembre 2016 - 09:44
di Aedenth
Buongiorno,

Non so se questo sia il modo migliore per farlo, ma usare il codice seguente dovrebbe funzionare.

Codice: Seleziona tutto

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: Barra rovesciata nell'esecuzione del comando

Pubblicato: 19 settembre 2016 - 15:24
presso il Municipio di Challans
Grazie, questa soluzione funziona!