dll - Standard input/output in C# process -
dll - Standard input/output in C# process -
my application app
using other application subapp
. when app
needs subapp
creating process subapp
, putting info subapp
stdin
, reading subapp
stdout
.
the problem subapp
using library writes stdout
.
fragment of subapp
code:
outsidelibrary.dosomeinitialization(); // <-- writes stdout stream input = console.openstandardinput(); stream output = console.openstandardoutput(); info = (dataformat)formatter.deserialize(input); //do job formatter.serialize(output, result);
is there way prevent code don't have writing stdout?
assuming want disable 3rd party component output , have command on rest of subapp code can next trick: redirect standard output null @ application bootstrap. when need write stdout temporary set standard output normal, write , set null again.
using system; using system.collections.generic; using system.linq; using system.text; using system.io; namespace stdio { class programme { static void main(string[] args) { console.setout(system.io.textwriter.null); console.writeline("this go > null"); writeoutput("this written standard output"); console.writeline("this go > null"); console.readkey(); } static void writeoutput(string somestring) { console.setout(console.out); stream output = console.openstandardoutput(); streamwriter sw = new streamwriter(output); sw.write(somestring); sw.flush(); sw.close(); output.close(); console.setout(system.io.textwriter.null); } } }
c# dll process stdout stdin
Comments
Post a Comment