-1

I want show output exit from command.

on my index.html.erb

<%= system("ls /home/username/") %>

Can, help me? i'am new on ruby and rails

codevb
  • 83
  • 1
  • 7
  • the problem is not very clear. Try `ls` or Dir["/path/to/search/*"]. Yout question looks like a https://stackoverflow.com/questions/1755665/get-names-of-all-files-from-a-folder-with-ruby – ggoha Sep 26 '19 at 16:55

1 Answers1

2

There's a lot to take into account when running a command like that in a production environment from workers and job queues to validating the machine that will run the command can run it and parsing the response. This type of thing should be done through a model inside a delayed job... but if you just want it to work and don't care about any of that then just do

<%= `ls home/username/` %>

Which will give you the result of running the command. The problem is that system returns only one of 3 possible values true false or nil and the execution's output is written to std_out.

To get the exit code of the command you run you could do:

<%= system("ls /home/username/"); $? %>

This will print the pid the ls command ran under and the exit status value.

robertoplancarte
  • 1,133
  • 11
  • 19