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 8773335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:16:07+00:00 2026-06-13T18:16:07+00:00

Ubuntu 12.04 Sinatra 1.3.3 Why does passing an argument to a ruby system call

  • 0

Ubuntu 12.04

Sinatra 1.3.3

Why does passing an argument to a ruby system call (%x[] or “) give me a ‘not found’ error in my sinatra app? The same code works fine in a normal ruby script running from the same directory.

I have a file test.rb like this

output = %x["ls"] 
p output

When I run it with “ruby test.rb” I get the contents of the current directory in the console, as expected.

If I modify the program to give an argument to the system call like so:

output = %x["ls sub_dir/"] 
p output

I get the contents of sub_dir, which sits in the current directory, as expected.

So far so good.

Now if I make a Sintra app with a post method:

require 'rubygems'
require 'bundler/setup'
require 'sinatra'

post "/" do
 output = x["ls"]
 return output
end

The response to a Post call to “/” returns the contents of the current directory, which includes ‘sub_dir’, as expected.

If I try to add the argument to the system call to the sinatra app like so:

require 'rubygems'
require 'bundler/setup'
require 'sinatra'

post "/" do
 output = x["ls sub_dir/"]
 return output
end

the response is nil and there is an error in the console:

sh: 1: ls sub_dir/: not found

Why does adding a parameter to a system call in my sinatra app cause it to crash, when the same code called from a plain ruby script, run from the same location works perfectly.

By the way, the ‘ls’ example shown here is not the command I really need to run, so please don’t explain a different way to get this information. I have an executable file that takes a file name as a parameter that I need to run, which behaves exactly the same way.

Thanks in advance!

  • 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-13T18:16:08+00:00Added an answer on June 13, 2026 at 6:16 pm

    I rewrote the sinatra app in another file in the same directory.

    Everything works as expected.

    I did not find the reason and I deleted the original file so that I won’t lose anymore time trying to figure it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm on Ubuntu 10.10/Ruby 1.9.2 Whatever I do, I can't get a sinatra app
On Ubuntu, I have install netbeans but it does not have any option to
I'm trying to run a Ruby application that requires Sinatra within Ubuntu 10.10. I'm
Ubuntu 11.04 64-bit [Tried on SuSE 32-bit, and got same error], I have gcc,
I'm just getting started with Sinatra. I'm running Ruby 1.9.2 on Ubuntu. After my
On Ubuntu - kernel 2.6.32.2 How to call already existing system call from user
OS : Ubuntu 12.04 Ruby : 1.9.3 I'd want to install Ruby with RVM
My Ubuntu Subversion server is not directly accessible to the Internet, 192.168.1.2 My public
I'm having a hard time getting Sinatra running on my local setup, Ubuntu Karmic
OS: ubuntu 11.10 Webserver: Apache Code: PHP I am trying to display the output

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.