How to pass response from one command as argument to another command?

Asked

Viewed 353 times

3

In linux I do something like to take the answer of a command and pass as argument to another:

./program `ruby -e"puts 'Oh' * 3"`

In case what is between the accents (ruby -e"puts 'Oh' * 3") will be executed and the return will be passed as an argument to the program.

How can I do this in Windows?

I thought of creating a batch file and running the program with argument, but I only need the command, do not run inside batch file

1 answer

4


If I understand what you need is to pass the outworking of command ruby as an argument for another program, in windows I believe that will need to store the value in a variable, ways I managed to get the result were:

Store the result in a file

This way will generate a file called resultado.tmp with the response of the command executed with ruby and then will set this value in the variable, soon after deleting the file (as it will no longer use):

ruby -e"puts 'Oh ' * 3" > resultado.tmp
set COMANDO_RUBY=<resultado.tmp
del resultado.tmp
programa.exe %COMANDO_RUBY%

FOR and usebackq

We have the option to use the FOR and he has the option called usebackq which causes whatever is between the accents to be executed:

`string que será executada`

The command should look like this:

FOR /F "usebackq" %i IN (`ruby -e"puts 'Oh ' * 3"`) DO SET COMANDO_RUBY=%i
programa.exe %COMANDO_RUBY%

Browser other questions tagged

You are not signed in. Login or sign up in order to post.