Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing output with the Exec task in msbuild

Tags:

msbuild

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) &lt; test.txt"/>

Any suggestions to get my example to work or alternatives?

like image 780
vicsz Avatar asked Dec 02 '22 04:12

vicsz


2 Answers

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"/>
like image 105
Xacron Avatar answered Dec 06 '22 14:12

Xacron


Just for your information :

  • ( &gt;) redirect the output to the file you specified after (overwritten if needed)

  • append the output to the file you specified after (not overwritten)

  • < redirect the standard INPUT to your command (basically pass the content of the file after to your command)

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) &gt; NUL"/>

If you want to redirect the errors as well, you use 2> like :

<Exec Command="cmd.exe /c sqlplus.exe  $(someCommandSpecificSettings) &gt; NUL 2&gt;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 ^^

like image 31
Benjamin Baumann Avatar answered Dec 06 '22 14:12

Benjamin Baumann