1

I am trying to create and append to a text file using PHP SSH2. The command I am sending is this:

$cmd = "cd $output_directory; cat > myfile.txt; echo \"My Text\" >> myfile.txt";

The file is created, but the text is not appended to it.

Appreciate any input as to where I am going wrong.

2
  • Your command works for me. Have you tried prepending "php" to the command? Commented Dec 11, 2018 at 4:13
  • Show the PHP code you use to run this $cmd. Also note that on my linux, cat >myfile.txt does not work. I have to do cat /dev/null >myfile.txt or my preferred >myfile.txt, no cat at all. This creates the empty file, I assume you want to do. Commented Dec 11, 2018 at 5:35

1 Answer 1

1

Try to change cat to touch to create file.

Example:

$cmd = "cd $output_directory; touch myfile.txt; echo \"My Text\" >> myfile.txt";
Sign up to request clarification or add additional context in comments.

Comments

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.