Introduction:
I have a 'magic' tool that can perform a command line operation on a machine if I provide the IP. The tool knows the OS that machine is using and executes the command on cmd/shell based on whether it is windows/linux and returns the output of the command back blindly.
C:> tool.exe 172.140.56.2 "ipconfig"
Assumptions:
- One OS per machine. Tool has no problem executing the command (whether it fails or not is a different problem)
- The OS is either windows or linux always.
- I determine the OS based on the command result
Problem:
Using this power of being able to execute a command, I want to determine the OS
My Solution:
Execute ipconfig command. If result is
-bash: ipconfig: command not found
It is linux.
Else if it is like this:
Windows IP Configuration
Ethernet adapter Local Area Connection:
...
then Windows.
Question:
I wanted to know if this is a foolproof way of doing this. I want a command which would not fail under certain scenarios. (say cygwin installed on windows allowing linux commands to succeed. Or ipconfig succeeding on linux under some special scneario.)
I can process the command output with some parser, if that helps in any way.
Just to clear any confusion. It can be ANY command. I ust used ipconfig in my example.