Suppressing output with the Exec task in msbuild - 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) < 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)
< 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) > 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 ^^

Ok, figured it out ... cmd.exe required a /c argument to work for what I wanted i.e.:
Also, it should be > instead of <
<Exec Command="cmd.exe /c sqlplus.exe $(someCommandSpecificSettings) > test.txt"/>

Try this:
<Exec Command="cmd.exe sqlplus.exe $(someCommandSpecificSettings) < test.txt >nul"/>

Related

What's in teamcity custom_script.cmd

I'm trying to dig into the depths of teamcity to get a better understanding of what its doing under the hood(and improve my own build knowledge). I noticed that when I run a build step it then executes its own .cmd which I presume wraps up the msbuild scripts. The problem is that whenever I look in the directory specified the file doesn't exist as I'm guessing it creates, executes then deletes almost instantly. Any suggestions on how to access the file? or what's inside?
Starting:D:\TeamCity\buildAgent\temp\agentTmp\custom_script5990675507156014131.cmd
A temporary file is created by TeamCity when you run add a Command Line Build Step with "Custom script" as runner.
The content of this file would be the Custom script you specified inside the user interface.
The produced output would be:
Step 1/1: Command Line (1s)
Starting: D:\TeamCity\buildAgent\temp\agentTmp\custom_script2362934300799611461.cmd
in directory: D:\TeamCity\buildAgent\work\c72dca7a7355b5de
Hello World
Process exited with code 0
In case anyone is wondering about this still, you can force echo back on.
Put as the first thing in the custom script
#echo on
this will undo the silent commands teamcity defaults to.
I looked around for a while but there seems to be no configuration variable in TeamCity allowing to keep generated files. Now if the commands executed take some time, e.g. more than a couple of seconds, you could just open the temp directory in explorer and start hitting F5 (refresh) from the moment a build is started until you see the .cmd file appear, then be quick and right-click it and select 'Edit' to open it in a text editor. If that is too hard you can try with the solution presented here: create a Powershell script with code like this:
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "D:\TeamCity\buildAgent\temp\agentTmp"
$watcher.Filter = "*.cmd"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true
$action = { $path = $Event.SourceEventArgs.FullPath
Add-content "D:\log.txt" -value (Get-Content $path)
}
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
while ($true) {sleep 1}
and run it. When the build starts and creates a cmd file, the powershell script will copy the content to d:\log.txt. This will still not work for very short-lived scripts though. In that case I'd just make the script last longer by adding something like
ping 127.0.0.1 -n 5 -w 1000 > NUL
which will make it last at least 5 seconds.

CMAKE add_custom_command: How to use my raw commands

I am trying to add some custom build commands to my vc2010 project by using ADD_CUSTOM_COMMAND. But:
[1] I just find that CMAKE will automatically insert much more code than I hvae expected.
For example, I want the command exactly to be:
"c:\Some Folder\MyTool.exe" -arg0 -arg1
The corresponding code in CMakeLists.txt is like:
add_custom_command( OUTPUT ${outfile}
COMMAND "c:\Some Folder\MyTool.exe" ARGS "-arg0 -arg1"
# COMMAND "\"c:\Some Folder\MyTool.exe\"" will FAIL to be parsed!
MAIN_DEPENDENCY ${infile}
VERBATIM)
but actually I got:
setlocal
c:\Some Folder\MyTool.exe "-arg0 -arg1"
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
This is not what I want. I have also tried the string: COMMAND "\"${MYTOOL_PATH}\" -arg0 -arg1", but CMake just failed to parse it because there is a quote in front of the string.
So it's bad I can't quote the command string because the path c:\Some Folder\MyTool.exe contains spaces.
[2] I also notice CMake will automatically expand my dependency pathes.
If I add to the command DEPENS "$(PATH_MACRO)", I will eventually get the dependency path automatically expanded by CMake: C:\MySolutionDir\$(PATH_MACRO); But I only want $(PATH_MACRO), because I will make sure visual studio understands what $(PATH_MACRO) refers to.
So here is my question:
How can CMake only accept my raw inputs, without auto expanding the path or inserting code I don't expect? I will make sure my inputs will be valid for visual studio. Thanks!
PS. My CMake version: 2.8.10.2. VS version: visual studio 2010 Ultimate
In case this helps someone. I was trying to get binary signing to work as a post-build step using signtool.exe but ONLY for Release builds. Only the uncommented syntax works, none of the others do. I'm kinda at a loss as to why some of the others do not work, but at least I found one that does. There seems to be some strange rules about when literal quotes are generated and when they are not, depending on what is inside the quoted expression. Perhaps someone can explain.
function(my_sign_binary TARGET)
#SET(COMMAND_LINE signtool sign $<TARGET_FILE:${TARGET}>)
add_custom_command(
TARGET ${TARGET}
POST_BUILD
COMMENT "Signing: ${TARGET}"
COMMAND "$<$<CONFIG:Release>:signtool>" "$<$<CONFIG:Release>:sign>" "$<$<CONFIG:Release>:$<TARGET_FILE:${TARGET}>>"
#COMMAND $<$<CONFIG:Release>:signtool.exe sign $<TARGET_FILE:${TARGET}>>
#COMMAND echo 1. signtool sign $<TARGET_FILE:${TARGET}>
#COMMAND echo 2. "$<$<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>>"
#COMMAND "$<$<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>>"
#COMMAND "$<$<CONFIG:Release>:signtool>" "$<$<CONFIG:Release>:\ sign\ $<TARGET_FILE:${TARGET}>>"
#COMMAND echo 3. $<$<CONFIG:Release>:"signtool sign $<TARGET_FILE:${TARGET}>">
#COMMAND "echo 4. $<$<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>>"
#COMMAND echo 5. [$<$<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>>]
#COMMAND $<$<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>>
#COMMAND $<$<CONFIG:Release>:${COMMAND_LINE}>
#COMMAND $<$<CONFIG:Release>:COMMAND_LINE>
#COMMAND $<$<CONFIG:Release>:"${COMMAND_LINE}">
#COMMAND $<CONFIG:Release>:signtool sign $<TARGET_FILE:${TARGET}>
#COMMAND echo 8. "${$<$<CONFIG:Release>:COMMAND_LINE>}"
#COMMAND ${"$<$<CONFIG:Release>:COMMAND_LINE>"}
)
endfunction()
For issue 1, try "c:\\Some Folder\\MyTool.exe" -arg0 -arg1. The ARGS parameter isn't required, but the point is to omit the quotes around the -arg0 -arg1.
For issue 2, since $(PATH_MACRO) is not an absolute path, CMake sees it as a path relative to your source directory. The best way to resolve this is probably to use "generator expressions", but without further info on your exact case, I can't provide a better answer.
For info on generator expressions, see the docs for add_custom_command.

How to use LuaDoc with LuaForWindows

The question is all in the title : how to use LuaDoc with LuaForWindows ?
In my Lua installation, I have a luadoc_start.bat but the command windows closes as soon as it opens.
From there I don't know what else can I do.
Any help ?
Thanks
For using luadoc in Lua For Windows, the command is like this:
luadoc_start.bat path\to\lua\file\name.lua
which is to be done in either the command prompt window, or powershell.
I get a doc file to properly generate but how to do it for the whole project? I understand there is a -d argument but I am not sure how to use it, none of my tries where successful.
For this task, you'll need to write a shell script. Here's a small powershell script.
$files = Get-ChildItem .\
foreach( $file in $files ) {
luadoc_start.bat "$file"
}
Where, you have to cd to the path\to\lua\file directory and run this PS1 file.
Just append pause line to luadoc_start.bat and you will see help screen.

Call a DOS command and redirect the output to a file

I'd like to have a macro in Visual Studio 2005 that calls a DOS command and redirects the output (stdout and stderr) to a file. Just calling the command and ">" redirecting it will not capture stderr, so there are two parts to this:
calling a DOS command
capturing both stderr and stdout to a file during that call
I'd then like to open this file in Visual Studio after the command completes.
I'm new to Visual Studio 2005 macro writing, and VB/VBA, so that's the kind of help that I'm looking for.
Thanks,
Mark
In DOS, > or 1> is stdout, and 2> is stderr. So, you could say
myprog.exe 1> out.txt 2> err.txt
to send them to separate files, or
myprog.exe 1>2> both.txt
to send them to both.
In VB/VBA, you could use the Shell command to call this (assuming you didn't know that already).

Output of sub-processes in DOS batch script not visible in Apache

I'm running Apache 2.2 (launched via console) on Vista. I have simple batch script in cgi-bin. Unfortunately, Apache does not seem to serve any content generated by sub-processes.
For example, given the following script:
#echo off
echo Content-Type: text/html
echo.
echo Visible in browser
cmd /c echo Hidden from browser
echo End of script
All three lines of text will appear in the console if executed directly from a command prompt. However the middle line ("Hidden from browser") will not appear if the script is launched from Apache.
This script is just illustrative -- I'm actually using the batch file to launch a number of separate console based applications (not cmd.exe)
What am I doing wrong?
I've been looking at this, over at :
Pipe Java output to calling script
FWIW, all of this C:\wamp\bin\apache\apache2.2.22\cgi-bin\testbat.bat's echo output appears in both the command window and the served webpage :
#echo off
rem This works in Wampserver's Apache cgi-bin...
rem http://localhost/cgi-bin/testbat.bat
echo Content-Type: text/html
echo.
echo ^<html^>^<head^>^</head^>^<body^>
echo ^<H1^>Hello world!!!^</H1^>
echo ^<PRE^>
FOR /F "usebackq delims==" %%i IN (`dir`) do echo %%i
echo ^</PRE^>
FOR /F "usebackq delims==" %%i IN (`cmd /c echo NOT hidden!`) do echo %%i
echo ^</body^>^</html^>
Many more details aside, this behavior happens when cmd is invoked via CreateProcess() with DETACHED_PROCESS, which is what Apache does in ap_cgi_build_command() through apr_proc_create() (reference to Apache 2.2.25 source code).
For some reason, the child processes from cmd are also spawned detached. This also happens in other situations (e.g., invoking WScript.CreateObject("WScript.Shell").Run() in the same context) which might or might not involve cmd in the background.
Unrelated lesson learned: if CreateObject(DETACHED_PROCESS) and I/O redirection (STARTF_USESTDHANDLES) are mixed together, results might be surprising.
As far as I know, there is no solution other than avoiding batch, WSH and others. The httpd team might look into this for a workaround in the future.
Maybe you need to redirect the output to your STDOUT. I haven't tried it on Windows machine, but you could try
cmd /c echo Hidden from browser >&1
or redirect it to a temp file and call type on the file.
It would work from the command line as expected but what are the applications that you are trying to run in apache's cgi-bin? I have not heard of Apache's cgi-bin being a batch file...and that could be a potential exploit...maybe the permissions are not set for the batch file...or that there is no plugin available for Apache to actually execute a batch file, think of the mod handlers used for ssl (secure sockets layer)...like this as an example found in Apache's config file...httpd.conf
<LoadModule ssl_module modules/mod_ssl.so>
....
<if mod_ssl>
....
</if>
This would explain why you cannot run a batch file as a cgi-bin script...