Java.lang.Runtime -
i have piece of code invokes instance of bash terminal through use of following --
proc = runtime.getruntime().exec("/bin/bash", null, working-dir);
and run unix commands on invoked instance of bash i'm using printwriter object --
printwriter out = new printwriter(new bufferedwriter(new outputstreamwriter(proc.getoutputstream())), true);
i'm using printwriter object execute commands in following fashion--
out.println("pwd"); out.println("ls >a.txt");
while both of commands seem work fine, have issue in case wherein construct command based on user input. being specific, i'm constructing command send files printer on network , i'm doing --
while ((strline = br.readline()) != null) { cmd= blah +blah +blah;//construction of command out.println(cmd); }
what happening in above piece of code br reading file contains files need printed , string having file name goes command , write onto printwriter object.
the issue im facing , guess there sort of queuing that's happening , printwriter object not passing on command invoked bash instance every time command constructed. @ end of day, if there 40 commands being constructed, 16-18 documents being printed. guess it because sending commands printer in 1 go resulting in loss.i want eliminate loss.
any pointers ??
thanks p1ng
try putting out.flush() in loop. flush buffer in bufferedwriter created.
another tip may avoid trying use single bash exec of commands , instead construct , execute command individually. consider using process builder instead of runtime.exec().
Comments
Post a Comment