Página 1 de 1

barra invertida en el comando ejecutar

Publicado: 13 de septiembre de 2016 - 12:27 p. m.
por el Ayuntamiento de Challans
Buen día,

Estoy intentando ejecutar un comando en el archivo pyton.py, pero cada vez que lo intento se duplican las barras invertidas y el comando falla.
El mismo problema persiste, c:\ se interpreta como c:\\.

El comando a ejecutar es:

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

commandsm=r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"
run(commandsm)
Todos estos comandos me devuelven lo siguiente:

Código: Seleccionar todo

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
¿Cómo puedo mantener intacto el carácter "c:\" en el comando de ejecución?

GRACIAS.

Re: Barra invertida en la ejecución del comando

Publicado: 13 de septiembre de 2016 - 16:01
por fludo67
Buen día,

¿Has probado a utilizar el carácter de escape \? (c:\\)

Código: Seleccionar todo

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

Re: Barra invertida en la ejecución del comando

Publicado: 16 de septiembre de 2016 - 11:09 a. m.
por el Ayuntamiento de Challans
Hola,

sí, y se ve así: c:////
(todas las barras invertidas están duplicadas)
:retorcido:

Re: Barra invertida en la ejecución del comando

Publicado: 19 de septiembre de 2016 - 09:44
por Aedenth
Buen día,

No sé si esta sea la mejor manera de hacerlo, pero usar el siguiente código debería funcionar.

Código: Seleccionar todo

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 invertida en la ejecución del comando

Publicado: 19 de septiembre de 2016 - 15:24
por el Ayuntamiento de Challans
¡Gracias, esta solución funciona!