Is there a way of calling POSIX functions that append/write to a file such as “<” and “<<” in a prefix as opposed to an infix manner?

StackOverflow https://stackoverflow.com/questions/8974522

Question

I am using the Google Chrome d8 shell version 3.7.7 to run a JavaScript application I have written for it and within which I need to create/write to a file. It seems that the only way to do I/O is to use the provided

os.system("program name",[arg1,arg2...],timeout1,timeout2)

The API is outlined in this header file: http://code.google.com/p/v8/source/browse/trunk/src/d8.h

So what I need is the name of a POSIX program that can be called in a prefix manner, that takes as arguments a file and a string and writes the string to the file. Is there such a program? If not does anyone see a way to work around this?

It seems that the following type of call cannot be made with the current API, as the < is an infix operator and does not seem to work as a prefix:

echo "foo" > file.txt

Any help would be greatly appreciated! Thanks.

Was it helpful?

Solution

Your immediate problem should be portably soluble just by using the shell:

os.system("sh", ["-c", "echo foo > file.txt"],timeout1,timeout2)

If you still want I/O redirection in a prefix-style command, then I wrote a tool for that some years ago: http://www.greenend.org.uk/rjk/2001/06/adverbio.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top