I am running an executable in a batch file with two parameters;
cmd /k ""executable" "param1" "param2""
This returns a string that I want to launch. I can't figure out how to set this return in a variable and subsequently launch it in IE.
Any ideas?
You can use the following syntax to capture the output of your executable into a variable:
Source
then you can pass the value on to IE like so:
I take it that the application code that determines the url is too complicated to be reproduced in a batch file directly, or the source to the executable has been lost. If not I personally would prefer to have the logic visible in the batch file itself.
If the returned string contains a single line you may use
FOR /F
to set the value of an environment variable. For example:s1.cmd
s2.cmd
Result
start %1 %2
Edit: Romulo A. Ceccon posted a much better solution which doesn't involve any file system access and dirty tricks. Left this here for reference (it works with command.com as well if you need 9x compatibility), but please prefer Romulo's solution.
Go through an environment variable you set by using an intermediate helper script you dynamically generate from a template. You will need write permissions somewhere, otherwise it cannot be done (the Windows command shell language is very, very limited.)
Let's call your helper script template
helper.tpl
with the following contents:Make sure that
helper.tpl
has only a single line (no trailing CRLF!) and make sure you don't have any spaces after the equals sign there.Now, in your main script, capture the output from your command into a temporary file (let's call it
my_output_file.tmp
):Then copy the contents of the helper template and the output together into your helper script, let's call it
my_helper_script.cmd
:Then evaluate the helper script in the current context:
Now the INTERMEDVAR variable is set to the first line of the output from "executable" (if it outputs more than one line, you're on your own...) You can now invoke IE:
And don't forget to clean up the created files:
This will obviously not work when invoked multiple times in parallel - you'll have to parametrize the temporary file and helper script names using the current cmd.exe's PID (for example) so that they won't overwrite each other's output, but the principle is the same.
However, if you can get a real shell, use that. cmd.exe is extremely cumbersome.