Seite 1 von 1

Backslash im Befehl run

Veröffentlicht: 13. September 2016 - 12:27 Uhr
vom Rathaus von Challans
Guten Morgen,

Ich versuche, einen Befehl in der Datei pyton.py auszuführen, aber jedes Mal werden meine Backslashes verdoppelt und der Befehl schlägt fehl.
Das gleiche Problem besteht weiterhin, c:\ wird als c:\\ interpretiert.

Der auszuführende Befehl lautet:

Code: Alle auswählen

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

Code: Alle auswählen

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

Code: Alle auswählen

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

Code: Alle auswählen

commandsm=r"powershell -NoProfile -NoLogo -NonInteractive -Command import-startlayout -layoutpath screenlayout.bin -mountpath c:\"
run(commandsm)
Alle diese Befehle liefern mir Folgendes zurück:

Code: Alle auswählen

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
Wie kann ich das Zeichen "c:\" im Ausführen-Befehl beibehalten?

DANKE.

Betreff: Backslash in Befehlsausführung

Veröffentlicht: 13. September 2016 - 16:01 Uhr
von fludo67
Guten Morgen,

Haben Sie versucht, das Escape-Zeichen \ zu verwenden? (c:\\)

Code: Alle auswählen

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

Betreff: Backslash in Befehlsausführung

Veröffentlicht: 16. September 2016 - 11:09 Uhr
vom Rathaus von Challans
Hallo,

ja, und es sieht so aus: c:////
(alle Backslashes sind verdoppelt)
:verdreht:

Betreff: Backslash in Befehlsausführung

Veröffentlicht: 19. September 2016 - 09:44 Uhr
von Aedenth
Guten Morgen,

Ich weiß nicht, ob das die beste Methode ist, aber mit dem folgenden Code sollte es funktionieren.

Code: Alle auswählen

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

Betreff: Backslash in Befehlsausführung

Veröffentlicht: 19. September 2016 – 15:24 Uhr
vom Rathaus von Challans
Vielen Dank, diese Lösung funktioniert!