Jump to content

New lines in console output


boen_robot

Recommended Posts

I need to write the output of a console program to a file. For that I use shell_exec() to execute the program and assign the result to a variable and file_put_contents() to save that output.The problem is new lines in the output appear as squares in the file when viewed with notepad. The output is fine in other editors (Wordpad for example).The output is echoed fine (looking at the source code with notepad, there are no squares, only new lines) and even copyed right (which is why I can't show you that square - pasting it in this textbox only results in a new line) but just not saved right.Here's a sample code to show the issue:

<?php$file = shell_exec('D:\exec.bat');echo file_put_contents('__test1__.html',$file);?>

Where exec.bat is:

@echo Offecho somethingecho something elseecho and moreecho and more

Any suggestions on making the output file appear right?

Link to comment
Share on other sites

For the sample I gave, this seems to solve the problem (cool move btw... I've never even heared about this type of thing).However, for my real problem (not this sample), modifying the command line command is not exactly feasable, though doable.Could you suggest any way that does it without modifying the command? Some adjustment to file_put_contents().... another similar function maybe?Thanks for your reply btw.

Link to comment
Share on other sites

I think there is a problem in notepad and the way it renders special characters. Default line separator in windows is CR and LF pairs, bur even when I write \r\n in file Notepad still shows that squares instead of new line. Other editors display the text correctly.

cool move btw... I've never even heared about this type of thing
that is very useful, '>' writes the output to a file and '>>' appends the output to a file
Link to comment
Share on other sites

Thanks for the info lulzim! I have his thing always happen, its just the wrong type of newline. I'm guessing your running this all on windows, but the newline is messing up somehow.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...