Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Ruby, run a cmd-command with a variable inside

+2 votes
asked Mar 20 by Stefan Klin (140 points)
Hi guys,

I'm a beginner with ruby and I've a simple question. I want to open a .png in irfan-view in full-screen-mode (/fs).
The name of the photo is stored in a variable (file_name) in my ruby script.
How can I implement the variable inside the cmd command?
Thank's a lot for every advice!!

file_name = "001.png"

system("i_view32.exe [file_name] /fs")

1 Answer

0 votes
answered Mar 26 by Gédéon KOUMAKO (180 points)

To insert the value of the file_name variable into the command, you can use string interpolation. Here's an example:

file_name = "001.png"
system("i_view32.exe #{file_name} /fs")

In this code, the #{file_name} expression is used to insert the value of the file_name variable into the command string. When the system method is called, the resulting command will be:

i_view32.exe 001.png /fs

This should open the 001.png file in IrfanView in full-screen mode.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.