2

I would like my code to run in the command line (cmd) and then output the result to a text file. The text file should then contain 'hello world'.

I tried

C:\wamp\bin\php\php5.3.13\php.exe -f "C:\wamp\www\hello.php"
1
  • 1
    if you add >answer.txt it should work Commented Nov 8, 2012 at 9:46

1 Answer 1

3

The answer is rather simple,

add > answer.txt to the command and it will be saved in answer.txt

so it will be

cd "C:\wamp\bin\php\php5.3.13"
php.exe -f "C:\wamp\www\hello.php" > answer.txt

the > says that all the output must be redirected

for more information see

http://technet.microsoft.com/en-us/library/bb490982.aspx

EDIT

If you also want to provide input you can do

cd "C:\wamp\bin\php\php5.3.13"
php.exe -f "C:\wamp\www\hello.php" < input.ini > answer.txt
Sign up to request clarification or add additional context in comments.

1 Comment

what if i want the result of the script open a window with the result in the txt. I have a script that runs ip addresses but i would like the results to be outputted example:C:\wamp\bin\php\php5.3.13>php.exe -f "C:\wamp\www\hello.php" input:test.ini output:results.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.