1

Using Python 2.7 on Windows 10. I want to use the Windows tftp client. Why would os.system() give a different result to typing the tftp command at the command prompt? (Use of 2.7 instead of 3, and the Windows TFTP client instead of looking for another library, are "because the boss says so".)

I don't know whether this is a Python question, a Windows 10 question, or specifically the Windows 10 TFTP client.

The TFTP client is installed on my machine. If I open a command shell and type tftp, I get a help message from the tftp client.

>tftp

Transfers files to and from a remote computer running the TFTP service.

TFTP [-i] host [GET | PUT] source [destination]
...

But if I try from Python, the tftp client is not found:

>python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('tftp')
'tftp' is not recognized as an internal or external command,
operable program or batch file.
1
>>>

There is a C:\Windows\system32\TFTP.EXE, and C:\Windows\system32 is on my path. If I try with a different exe file from C:\Windows\system32, for example tar.exe, it works:

>>> os.system('tar')
tar: Must specify one of -c, -r, -t, -u, -x
1

There is a "which" utility on my machine, and it also does not find a .exe file for tftp, but it does find tar, and this really puzzles me. I do note that TFTP.EXE has the extension in upper case, whereas tar.exe is lower case, but Windows has never been case-sensitive as far as I know, and anyway I have tried both commands in upper and lower case.

Also, I thought that os.system() just passed the string to the system for execution. So surely Windows should find the utility, if the same command typed at the shell prompt works?

I also tried os.system("cmd /c tftp") with the same results -- works if I type it at the command prompt, not from os.system(). Putting quotes around tftp, or adding an explicit .exe (or .EXE) doesn't work either.

fpeelo
  • 372
  • 2
  • 10

1 Answers1

0

In Windows 10, to run tftp.exe from Python, I have to run C:\Windows\SysNative\tftp.exe

>>> os.system("c:\\windows\\system32\\tftp")
'c:\windows\system32\tftp' is not recognized as an internal or external command,
operable program or batch file.
1
>>> os.system("c:\\windows\\sysnative\\tftp")

Transfers files to and from a remote computer running the TFTP service.
...

C:\windows\system32\tftp.exe exists but there is no C:\windows\sysnative\tftp.exe on this machine. In fact there is no sysnative directory, even looking for system & hidden files from a shell started as an administrator. So I do not understand this. But it works.

To me this seems like a hack that MS have to really discourage use of tftp.exe, so maybe I should take the hint.

fpeelo
  • 372
  • 2
  • 10