0

I have a dual boot machine (windows/ubuntu) and I need to automate the toggle between them, so first I need to check on which OS am I right now in programmatic way (background: there will be 2 different tasks that will reach the machine from remote, each designed for their specific OS - linux or windows - and so I'll need to restart accordingly).

Is there a good way to do so other then look for a predefined anchor file/path ?

  • You should state the language you are working with. This is usually a scripting task so... possible duplicate of [How to detect the OS from a Bash script?](https://stackoverflow.com/questions/394230/how-to-detect-the-os-from-a-bash-script) – jww Mar 06 '18 at 11:40
  • There is no specific language - as long as it works. Main problem in scripting is adjusting the script to the OS (e.g run .sh in linux and .bat in windows) - when it's unknown –  Mar 06 '18 at 13:41
  • You can use the same bash script on linux and windows, if you install cygwin on your windows machine. – Yavor Mar 06 '18 at 14:02

1 Answers1

0

You can use C preprocessor to identify the OS, something liḱe in your translation unit can help you.

#ifdef __linux__ 
    //linux 
#elif _WIN32
    //windows 
#elif _MACH__
   //Mac
#else

#endif
danglingpointer
  • 4,708
  • 3
  • 24
  • 42