Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:49:37+00:00 2026-06-03T12:49:37+00:00

Say I have a web application, with some sort of system execution. I’m going

  • 0

Say I have a web application, with some sort of system execution. I’m going to use Ruby for this example. This app could be portable and installed on either a Windows or Unix server. If the app uses system commands, is there a way to distinguish what platform the server is, then maybe catch in an if statement?

Theoretically like this:

os_check = `checkos` # System ticks to execute through the shell
                     # using fake command

if os_check == 'unix'
  # Run Unix Commands
  `ls -la`
else if os_check == 'dos'
  # Run DOS commands
  `dir`
else
  puts 'OS not detectable'
end

EDIT

I’m not looking for Ruby specifically (removed the tag). That was an example. I was hoping for a shell command that could execute in both environments and be variable based on what the OS is. I actually have to replicate this sort of function in several languages. Sorry for any confusion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:49:40+00:00Added an answer on June 3, 2026 at 12:49 pm

    Try checking the RUBY_PLATFORM global constant:

    case RUBY_PLATFORM
      when /win32/ then # Windows, use "dir"
      # when /darwin/ then # Mac OS X
      # when /linux/ then # Linux
      else # Assume "ls" on all other platforms
    end
    

    [Edit] Per your updated question, you might be able to issue the system command echo /? and parse the output to determine the host OS. The “echo” command should exist on most systems but Windows interprets the /? switch as the “help” message whereas UNIX OSes simply echo those characters. For example (again in Ruby, just to demonstrate the general strategy):

    def detect_host_operating_system
      (%x{echo /?} =~ /^\/\?\r?\n$/) ? 'unix' : 'windows'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web-application. As part of this, I need users of the app
Let's say we have a grails web application exposing several resources. tags urls users
I have a web application containing two web services, let's say PublicHello.asmx and RestrictedHello.asmx
Let's say I have a Tomcat and a web application on it with index.html
When creating a web application, and lets say you have a User object denoting
Let say, I have a web application that allows users to upload images and
Say, for example, I have many web applications using the same class library compiled
Say I have a web service http://www.example.com/webservice.pl?q=google which returns text google.com. I need to
Say you have a web form with some fields that you want to validate
Let's say I have an web CMS type application, and an EDM model with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.