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

3

In linux I do something to get the response of one 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 argument to program .

How can I do this in Windows?

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

    
asked by anonymous 04.01.2017 / 16:06

1 answer

4

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

Store the result in a file

In this way it will generate a file named resultado.tmp with the response of the command executed with ruby and then it will set this value in the variable, soon after deleting the file (since 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 FOR and it has the option called usebackq that makes whatever is between the accents is 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%
    
04.01.2017 / 23:23