run command line command within ruby, using ruby variable

Jackson Gong

I need to run a ruby script to compile and save a csv file, whose path will be determined by the ARGV I give the script. I want ruby to automatically open that file (using open filepath inside backticks) at the end, but the filepath variable will be dynamic. How do I give the value of the filepath to the command inside backticks? Thank you!!

Jyrki

You can use string interpolation in backticks, just like with double quoted strings:

`open #{filepath}`

Side note: it’s a good idea to use Shellwords.escape so that e.g. spaces inside filepath won’t break your code:

require "shellwords"

`open #{Shellwords.escape(filepath)}`

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Parse command line arguments in a Ruby script

From Dev

Ruby command line gem search returns no results

From Dev

fdisk command run on terminal but not run with ruby script

From Dev

How to pass URL in ruby command line?

From Dev

How can I run a command line command from within a ruby file?

From Dev

Ruby Command Line Implicit Conditional Check

From Dev

Run a command line using golang?

From Dev

Parse multiple command line options in Ruby using OptionParser

From Dev

How to pass parameters to ruby command line script

From Dev

Command to run a RUBY cron job on JUSTHOST

From Dev

How can I run this curl command in Ruby?

From Dev

How can I run a ruby file in command line from Java?

From Dev

Ruby command line gem search returns no results

From Dev

Changing directory in ubuntu with Ruby and a command line tool

From Dev

fdisk command run on terminal but not run with ruby script

From Dev

list of arguments for executing ruby from command line

From Dev

No return on command line when running Ruby script

From Dev

How to run windows command using ruby script?

From Dev

Running Ruby Script/Program and interacting in command line

From Dev

How to run Ruby scripts in Command Line?

From Dev

Ruby : Pass array in command line argument

From Dev

Ruby Script to Command Line Tool

From Dev

Ruby inline storage with gets command line support

From Dev

How to access the Ruby Command line in ubuntu 14.04?

From Dev

Make ARGV[0] optional in command line Ruby

From Dev

Pass variable inside ruby command?

From Dev

Scripting bash with Ruby and Variables to run FFMPEG command

From Dev

run specific version of ruby script if command line argument is entered

From Dev

How to run a command on windows using Ruby

Related Related

  1. 1

    Parse command line arguments in a Ruby script

  2. 2

    Ruby command line gem search returns no results

  3. 3

    fdisk command run on terminal but not run with ruby script

  4. 4

    How to pass URL in ruby command line?

  5. 5

    How can I run a command line command from within a ruby file?

  6. 6

    Ruby Command Line Implicit Conditional Check

  7. 7

    Run a command line using golang?

  8. 8

    Parse multiple command line options in Ruby using OptionParser

  9. 9

    How to pass parameters to ruby command line script

  10. 10

    Command to run a RUBY cron job on JUSTHOST

  11. 11

    How can I run this curl command in Ruby?

  12. 12

    How can I run a ruby file in command line from Java?

  13. 13

    Ruby command line gem search returns no results

  14. 14

    Changing directory in ubuntu with Ruby and a command line tool

  15. 15

    fdisk command run on terminal but not run with ruby script

  16. 16

    list of arguments for executing ruby from command line

  17. 17

    No return on command line when running Ruby script

  18. 18

    How to run windows command using ruby script?

  19. 19

    Running Ruby Script/Program and interacting in command line

  20. 20

    How to run Ruby scripts in Command Line?

  21. 21

    Ruby : Pass array in command line argument

  22. 22

    Ruby Script to Command Line Tool

  23. 23

    Ruby inline storage with gets command line support

  24. 24

    How to access the Ruby Command line in ubuntu 14.04?

  25. 25

    Make ARGV[0] optional in command line Ruby

  26. 26

    Pass variable inside ruby command?

  27. 27

    Scripting bash with Ruby and Variables to run FFMPEG command

  28. 28

    run specific version of ruby script if command line argument is entered

  29. 29

    How to run a command on windows using Ruby

HotTag

Archive