Mark Tomlin
Mark Tomlin

Reputation: 8943

Read file output into a variable

I have the output of a file that I would like to make a varabile in a batch program. How do I go about doing this? I would like to take the output of this, php file.php and put it into a variable named %this%. How do I do that?

[edit] Removed tags, this question is meant to provide an example for batch variable handling only. The fact that I used PHP was just an example, it could just as well be a python file that I'm reading the output from, or a regular executable.

Upvotes: 2

Views: 966

Answers (2)

Joey
Joey

Reputation: 354864

for /f "delims=" %%x in ('php file.php') do set "this=%%x"

Upvotes: 3

netiul
netiul

Reputation: 2769

@ECHO OFF
php file.php > output.txt
set /p OUTPUT= < output.txt
del output.txt

echo %OUTPUT%

Upvotes: 5

Related Questions