2016-07-26 10 views
-1

Ich versuche tftp von einem Python-Skript ausführen. Ich habe es als Windows 10 Feature (http://www.trishtech.com/2014/10/enable-tftp-telnet-in-windows-10/) aktiviert, so dass ich es über die Befehlszeile ausführen kann. Aber wenn ich versuche, es durch Python auszuführen, erhalte ich Fehler. Ich habe 3 Methoden versucht, sie aufzurufen: os.system, subprocess.call, subprocess.Popen und als 'control' nutzten diese Subprozesse, um 'dir' erfolgreich aufzurufen. Ich habe auch versucht, tftp vom vollständigen Pfad anzurufen. Code und Ausgabe eingefügt unten. Ich habe Verzögerungen und etwas Drucken hinzugefügt, um das Parsen zu erleichtern.Wie führe ich "Windows-Funktionen" über Python aus?

Meine Vermutung ist, dass bei Verwendung dieser Methoden die zusätzlichen "Windows-Funktionen", die ich aktiviert habe, nicht Teil der Umgebung sind, die Python sieht. Aber ich bin nicht sicher, wie man die Umgebung spezifiziert, um die Eigenschaft mit einzuschließen!

call("dir", shell = True) 
print "*******************************************" 
time.sleep(1) 
call("tftp", shell = True) 
print "*******************************************" 
time.sleep(1) 
call("C:\Windows\System32\\tftp.exe", shell = True) 
print "*******************************************" 
time.sleep(1) 
Popen("dir", shell = True) 
print "*******************************************" 
time.sleep(1) 
Popen("tftp", shell = True) 
print "*******************************************" 
time.sleep(1) 
Popen("C:\Windows\System32\\tftp.exe", shell = True) 
print "*******************************************" 
time.sleep(1) 
os.system("dir") 
print "*******************************************" 
time.sleep(1) 
os.system("tftp") 
print "*******************************************" 
time.sleep(1) 
os.system("C:\Windows\System32\\tftp.exe") 
print "*******************************************" 
time.sleep(1) 

Und die Ausgabe ich erhalte, ist:

Directory of C:\[REDACTED] 

07/26/2016 11:05 AM <DIR>   . 
07/26/2016 11:05 AM <DIR>   .. 
07/26/2016 11:05 AM    1,724 [REDACTED].py 
07/26/2016 11:05 AM    1,828 [REDACTED].pyc 
07/23/2016 05:36 PM    1,933 prep_for_bootload.py 
07/26/2016 07:52 AM    13 s.bat 
07/26/2016 11:19 AM    1,449 scrap.py 
07/26/2016 10:38 AM    672 test_script.py 
07/26/2016 10:39 AM    90 upload_script.bat 
       7 File(s)   7,709 bytes 
       2 Dir(s) 222,286,884,864 bytes free 
******************************************* 
'tftp' is not recognized as an internal or external command, 
operable program or batch file. 
******************************************* 
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command, 
operable program or batch file. 
******************************************* 
******************************************* 
Volume in drive C has no label. 
Volume Serial Number is 2AC7-8D0E 

Directory of C:\Users\[REDACTED] 

07/26/2016 11:05 AM <DIR>   . 
07/26/2016 11:05 AM <DIR>   .. 
07/26/2016 11:05 AM    1,724 [REDACTED] 
07/26/2016 11:05 AM    1,828 [REDACTED] 
07/23/2016 05:36 PM    1,933 prep_for_bootload.py 
07/26/2016 07:52 AM    13 s.bat 
07/26/2016 11:19 AM    1,449 scrap.py 
07/26/2016 10:38 AM    672 test_script.py 
07/26/2016 10:39 AM    90 upload_script.bat 
       7 File(s)   7,709 bytes 
       2 Dir(s) 222,286,884,864 bytes free 
******************************************* 
'tftp' is not recognized as an internal or external command, 
operable program or batch file. 
******************************************* 
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command, 
operable program or batch file. 
Volume in drive C has no label. 
Volume Serial Number is 2AC7-8D0E 

Directory of C:\Users\[REDACTED] 

07/26/2016 11:05 AM <DIR>   . 
07/26/2016 11:05 AM <DIR>   .. 
07/26/2016 11:05 AM    1,724 [REDACTED] 
07/26/2016 11:05 AM    1,828 [REDACTED] 
07/23/2016 05:36 PM    1,933 prep_for_bootload.py 
07/26/2016 07:52 AM    13 s.bat 
07/26/2016 11:19 AM    1,449 scrap.py 
07/26/2016 10:38 AM    672 test_script.py 
07/26/2016 10:39 AM    90 upload_script.bat 
       7 File(s)   7,709 bytes 
       2 Dir(s) 222,286,884,864 bytes free 
******************************************* 
'tftp' is not recognized as an internal or external command, 
operable program or batch file. 
******************************************* 
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command, 
operable program or batch file. 
******************************************* 
+0

Haben Sie versucht, zu lokalisieren, wo' tftp' Befehl ist, und nur manuell aufrufen es von seinem vollständigen Speicherort? dh, wenn es in 'c: \ windows \ tftp.exe 'installiert ist, rufen Sie es von Python mit seinem vollständigen Pfad ab. – FrankerZ

+0

Ja, das habe ich auch ausprobiert - ich füge das zu meinem OP hinzu: – MCM

+0

'" \ t "' ist ein Tab-Zeichen, kein Backslash, gefolgt von einem "t". –

Antwort

0

Siehe Antwort von: @eryksun für die richtige Antwort. Zitiert hier:

"Um in jedem Fall zu arbeiten, verwenden Sie system32 = 'SysNative' wenn platform.architecture() [0] == '32bit' sonst 'System32'. Dann erstellen Sie den voll qualifizierten Pfad als tftp_path = os. path.join (os.environ ['SystemRoot'], system32, 'TFTP.EXE') "

+0

Sie können eine Antwort in Ihren eigenen Worten schreiben. Dies ist ein sehr häufiges Problem, aber ich denke nicht, dass es einfach ist, nach Antworten zu suchen, da es eine fundamentale Trennung zwischen dem, was Sie tun wollen, und dem zugrunde liegenden Problem - der Virtualisierung des Dateisystems - gibt WOW64. – eryksun