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.