std::ostringstream printing the address of the c-string instead of its content

The expressionstd::ostringstream() creates a temporary, and operator<< which takes const char* as argument is a free function, but this free function cannot be called on a temporary, as the type of the first parameter of the function is std::ostream& which cannot be bound to temporary object. Having said that, <<std::ostringstream() << “some data” resolves to … Read more

How to pass variables as stdin into command line from PHP

I’m not sure about what you’re trying to achieve. You can read stdin with the URL php://stdin. But that’s the stdin from the PHP command line, not the one from pdftk (through exec). But I’ll give a +1 for proc_open() <?php $cmd = sprintf(‘pdftk %s fill_form %s output -‘,’blank_form.pdf’, raw2xfdf($_POST)); $descriptorspec = array( 0 => … Read more

Capture both stdout and stderr in Bash [duplicate]

There’s a really ugly way to capture stderr and stdout in two separate variables without temporary files (if you like plumbing), using process substitution, source, and declare appropriately. I’ll call your command banana. You can mimic such a command with a function: banana() { echo “banana to stdout” echo >&2 “banana to stderr” } I’ll … Read more

Open an IO stream from a local file or url

open-uri is part of the standard Ruby library, and it will redefine the behavior of open so that you can open a url, as well as a local file. It returns a File object, so you should be able to call methods like read and readlines. require ‘open-uri’ file_contents = open(‘local-file.txt’) { |f| f.read } … Read more

Error “This stream does not support seek operations” in C#

You probably want something like this. Either checking the length fails, or the BinaryReader is doing seeks behind the scenes. HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); WebResponse myResp = myReq.GetResponse(); byte[] b = null; using( Stream stream = myResp.GetResponseStream() ) using( MemoryStream ms = new MemoryStream() ) { int count = 0; do { byte[] buf = … Read more