BerryWorksSoftware / edi-json

Serializing EDI as JSON
https://github.com/BerryWorksSoftware/edi-json
100 stars 32 forks source link

option to send output to stdout instead of a file #5

Open harriettxing opened 5 years ago

harriettxing commented 5 years ago

Can the the output be directed to stdout instead written to an output file?

canabrook commented 5 years ago

Yes, but not with the provided driver program. The Java API accepts a java.io.Writer object to handle the output, which can be directed to stdout. The sample driver program, for which the Java source is provided, creates a FileWriter using a filename from the command line. But you could modify the driver program to write to stdout instead. This sounds like it might be a useful feature in a new version; it would allow the content to be piped between Linux tasks without going into a file. Is that what you had in mind?

harriettxing commented 5 years ago

Yes. I am using the tool in php. When it writes to a file, I delete the file after loading the json into a php variable. $out = shell_exec('java -jar edireader-json-basic-5.5.14.jar '.$filename.' '.$outfilename); $string = file_get_contents($outfilename); $json_a = json_decode($string, true); exec("rm ".$outfilename);

If the output can be directed to stdout, I could avoid using the file. $out = shell_exec('java -jar edireader-json-basic-5.5.14.jar '.$filename.' '.$outfilename); $json_a = json_decode($out, true);

canabrook commented 5 years ago

I am creating a new release with a change to the command line driver to allow output to be written to stdout, and also for input to be read from stdin. It should be ready in a few days.