Page 1 of 1

backslash in command run

Published: September 13, 2016 - 12:27 PM
by the Challans Town Hall
Good morning,

I'm trying to run a command in the pyton.py file, but each time my backslashes are doubled and the command fails.
The same problem persists, c:\ is interpreted as c:\\.

The command to execute is:

Code: Select all

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

Code: Select all

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

Code: Select all

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

Code: Select all

commandsm=r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"
run(commandsm)
All these commands return the following to me:

Code: Select all

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
How can I keep the "c:\" character intact in the run command?

THANKS.

Re: Backslash in command run

Published: September 13, 2016 - 4:01 PM
by fludo67
Good morning,

Have you tried using the escape character \? (c:\\)

Code: Select all

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

Re: Backslash in command run

Published: September 16, 2016 - 11:09 AM
by the Challans Town Hall
Hello,

yes, and so it looks like this: c:////
(all backslashes are doubled)
:twisted:

Re: Backslash in command run

Published: September 19, 2016 - 09:44
by Aedenth
Good morning,

I don't know if this is the best way to do it, but using the following code should work.

Code: Select all

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 in command run

Published: September 19, 2016 - 3:24 PM
by the Challans Town Hall
Thank you, this solution works!