Reading php://stderr - stderr

I want to read php://stderr. How can do it?
Do php://stderr and STDERR write to the same file? Because after writing to php://stderr I tried reading STDERR using stream_get_contents but I did not get any data?
Also while writing to php://stderr using file_put_contents do we need to use APPEND flag so that the data is not overwritten.

It is recommended that you simply use the constants STDIN, STDOUT and STDERR instead of manually opening streams using these wrappers.
http://www.php.net/manual/en/wrappers.php.php

You can't read from php://stderr.
Building on the answer of #user647772:
It is recommended that you simply use the constants STDIN, STDOUT and STDERR instead of manually opening streams using these wrappers.
...
php://stdin is read-only, whereas php://stdout and
php://stderr are write-only.
Source: http://www.php.net/manual/en/wrappers.php.php
Also since php://stderr essentially points to a stream using the APPEND is not needed because there is nothing to overwrite (since it's not a file). Streams can not be overwritten by nature. You just put something in or get something out of a stream.

Related

How to print out ASCII to a separate file.

I am trying to print data using
*EL PRINT
to a separate file other that jobname.dat file.
Is there any way to do this?
PS: I know how to export the data from the odb file.
Thanks
As far as I know you can't reroute that kind of input-file keyword output request to a different file. I've listed some alternatives below:
As you mention, you can script it using the Abaqus/Python API.
You can manually print results to a file of your choosing from the Viewer.
You can access the results file for postprocessing using a Fortran or C++ program (search for ABQMAIN).
You can access results and write them to a file of your choosing during the analysis using the Fortran subroutine URDFIL.

Does Ruby on Rails have read stream for files?

Does rails have a way to implement read streams like Node js for file reading?
i.e.
fs.createReadStream(__dirname + '/data.txt');
as apposed to
fs.readFile(__dirname + '/data.txt');
Where I see ruby has
file = File.new("data.txt")
I am unsure of the equivalent in ruby/rails for creating a stream and would like to know if this is possible. The reasons I ask is for memory management as a stream will be delivered piece by piece as apposed to one whole file.
If you want to read a file in Ruby piece-by-piece, there are a host of methods available to you.
IO#each_line/IO::foreach, also implemented in File to iterate over each line of the file. Neither reads the whole file into memory; instead, both simply read up until the next newline, return, and pause reading, barring a possible buffer.
IO#read/IO::read takes a length parameter, which allows you to specify for it to read up to length bytes from the file. This will only read that many, and not the whole thing.
IO::binread does the same as IO::read, but will open the file in binary mode.
IO#readpartial appears to be very similar or identical to IO#read, but is also worth looking at.
IO#getc and IO#gets both read from the file until they reach the end of what they'll return, as far as I can tell.
There are several more that I'm looking for right now.

how to overwrite, or delete the file, used by writefile() calls?

I use the following to save screen output to a file
writefile("file.txt"),
tex(expression),
closefile()
The above sends the output of the tex() to the file automatically. which is all and well and what I want. (side-point: It also sends an annoying NIL line each time to the file, which I had to parse put later).
Now, when running the above code again, the file is appended to, which is not what I want. I want to either overwrite the file each time, or if there is a way to delete the file, so I can call delete on it before.
I looked at help and not able to find a command to delete a file, and I also see no option to tell writefile() to overwrite the file?
Is there an option or way around this? I am on windows 7, Maxima version: 5.36.1
Lisp: SBCL 1.2.7
I guess you are trying to capture the output of tex into a file. If so, here are a couple of other ways to do it:
tex (expr, destination);
where destination is either a file name (which is appended) or a stream, as created by opena or openw and closed by close. By the way, destination could be false, in which case tex returns a string.
with_stdout (destination, tex (expr));
where again destination is either a file name (which is appended or clobbered, as determined by the global flag file_output_append) or a stream.
with_stdout could be useful if you want to mix in some output not generated by tex, e.g., print("% some commentary");.

How to redirect stdout to file in Lua?

I'm trying to redirect stdout in Lua (5.1) to a file instead of to console.
There is a third-party API (which I cannot modify) containing a function that prints out a serialized set of data (I do not know which function does the printing, assume some sort of print())
This data is far too verbose to fit on the screen I have to work with (which cannot be scrolled) so I want to have the function's output be directed to a file instead of to console.
I do not have the ability to patch or manipulate Lua versions.
My thought was to change stdout to a file using the poorly documented io.output() file, but this does not seem to work at all.
io.output("foo") -- creates file "foo", should set stdout to "foo"?
print("testing. 1, 2, 3") -- should print into "foo", goes to console instead
Does anyone know of any way to force a functions output into a file, or force all stdout into a file instead of console? TIA.
You need to use io.write method instead of print. It works in a similar way, but doesn't separate parameters with a tab. io.write respects io.output, but print doesn't.
-- save, might need to restore later
real_stdout = io.stdout
file = io.open ('stdout.log', 'w')
io.stdout = file
.... -- call external API
-- restore
io.stdout = real_stdout

How to check if stdin buffer is empty at TCL?

With fconfigure you can get and set channel options. -buffering specifies the type of buffering, and by default it is line for stdin.
Is there a way to check if the buffer at stdin is empty or not?
Please see this question: How to check if stdin is pending in TCL?
Obviously you could set the channel mode to non-blocking and read from it. If the read returns 0 length then nothing was available. However, I suspect you mean to test for data present but not a complete line given your mentioning of the line buffering there. The fblocked command tests a channel for this. See fblocked(1) for the details but for a line buffered channel this lets you know that an incomplete line is present.
Another useful command when reading stdin, if you are reading interactive script commands is to use the info complete command. With this you can just accumulate lines until info complete returns true then evaluate the whole buffer in one.
You can check Tcl's input buffer with chan pending input stdin (requires at least Tcl 8.5). This does not indicate whether the OS has anything in its buffers though; those are checked by trying to read the data (gets or read) or by using a script that triggers off of a readable fileevent, when at least one byte is present. (Well, strictly what is actually promised is that an attempt to read a single byte won't block, but it could be because of an error condition which causes immediate failure. That's the semantics of how OS-level file descriptor readiness works.)
The -buffering option only affects output channels; it's useless on stdin (or any other read-only channel) and has no effect at all. Really. (It is, however, too much trouble to remove.)
I know this is an old question but it sparked some research on my end and I found a function called fileevent which calls an event handler when the stream, i.e. stdin, has something in it that can be read. It may be helpful.
Source: http://wiki.tcl.tk/880

Resources