I'm running a command using the msbuild "Exec" task. However I do not want the stdio output generated from the command to appear in the console, is there anyway to suppress it?
Maybe something along the lines of using the Exec task to call "cmd.exe" with my command exe is a target , and then using ">" to redirect the output somewhere else. (However I'm unable to get this solution to work).
i.e.
<Exec Command="cmd.exe sqlplus.exe $(someCommandSpecificSettings) < test.txt"/>
Any suggestions to get my example to work or alternatives?
The best way to suppress Standard Output and Standard Error Output from Exec tasks or any task that inherits from ToolTask is to lower the importance of the output. That way if you're debugging your build, these output won't be completely hidden because you're redirecting them to nul.
<Exec Command="sqlplus.exe" StandardOutputImportance="low" StandardErrorImportance="low"/>
Just for your information :
(
>
) redirect the output to the file you specified after (overwritten if needed)
append the output to the file you specified after (not overwritten)
With your code, you create (once) and replace each time a test.txt file. Instead of using a filename, you can use NUL that means redirect to nowhere. This will not create the file (which could be huge in some case) :
<Exec Command="cmd.exe /c sqlplus.exe $(someCommandSpecificSettings) > NUL"/>
If you want to redirect the errors as well, you use 2> like :
<Exec Command="cmd.exe /c sqlplus.exe $(someCommandSpecificSettings) > NUL 2>errors.txt"/>
Also note that you can redirect the stderr to stdout using 2>&1, thus
> NUL 2>&1
will redirect everything to nowhere.
Hope this clarifies your mind ^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With