Informatica Command Task - if-statement

I asked this question on the Informatica forums, but no one knew the answer, so now I'm coming here for some help.
To my understanding, anything in a "post-session success command" field should be passed to the appropriate command interface and executed. However, when I use an IF statement, it fails. Any ideas?
"IF 1==1 echo.bob >> f:\filename.txt"
This works when I type it manually into the terminal (DOS in this case). But when I throw it into a reusable command task, I get this:
ERROR
POST-SESS
CMN_1949
Error: [Pre/Post Session Command] Process id 2996. The shell command failed with exit code 1.
PS: Using 9.5.1 Hotfix 1

I think the problem is not in how Informatica executes commands. The problem lies in how DOS return error codes, and specifically that some commands, like IF and ECHO does'nt. (The return code Informatica picks up from DOS can be seen with echo %ERRORLEVEL% in DOS, and I'll use the name DOS here for convenience even though under Windows now this is'nt strictly correct)
Run these commands in succession:
REM "cd" sets ERRORLEVEL => ERRORLEVEL is set to 0
cd c:\
echo %ERRORLEVEL%
REM "echo" does not set ERRORLEVEL => ERRORLEVEL is left unchanged
echo.bob >> c:\filename.txt
echo %ERRORLEVEL%
REM "echo" does not set ERRORLEVEL => ERRORLEVEL is left unchanged
echo.bob >> c:\thisdirdontexist\filename.txt
echo %ERRORLEVEL%
The first CD set a return code, in this case to 0.
The following ECHO (with or without the IF test) does not change the return code, thus it remains 0 even though the last ECHO fails.
If the first CD command would have returned an error;
#echo off
REM "cd" sets ERRORLEVEL => ERRORLEVEL is set to 1
cd xxxxxx
echo %ERRORLEVEL%
then all the subsequent ECHO would return 1 and Informatica would fail them both.
This said it is still strange since each post-session success command in Informatica is executed under its own cmd-shell, so the initial ERRORLEVEL for every command should allways be 0. I can't explain that and unfortunately I can't actually test this in Informatica as we run under UNIX, but I'm pretty sure this is at least part of the problem.
To get around the problem you should make sure that you set the "Fail task if any command fails" option on the property-tab. This makes Informatica use the cmd/c option and since this set a proper return code Informatica should be able to pick up the error (or success) correctly. If this still doesn't work properly try change the command yourself to:
cmd /c "IF 1==1 echo.uncle >> c:\filename.txt"

Related

What is the purpose of echo command after executing a program?

Why do we exit issuing an echo command while executing a program?
As far as I know, the echo command for console windows is:
$ echo $
And for windows is:
$ echo %ERRORLEVEL%
When the child process ends, the set variable ERRORLEVEL contains an integer returned by it. ERRORLEVEL is measured 0 if the process was successful (i.e. return 0). OTOH, 1 or greater if the process encountered an error.
However, I don't know what do you exactly mean by:
echo command after executing a program
I never ran this command neither I've seen anywhere.

want to apply the try catch for the batch file(alternative of try catch)

i want to dump the data excluding contenttype. I am gerring error so that i wnt apply try catch to code.
So that i can find out what error i am facing.
set /p pathName=Enter The path where you want to take backup:%=%
#echo %pathName%
set d=%date:~-4,4%_%date:~-7,2%_%date:~0,2%
set d=%d: =_%
set t=%time:~0,2%_%time:~3,2%_%time:~6,2%
set t=%t: =0%
md %pathName%\media
try{
python dtz/manage.py dumpdata -e contenttype>> %pathName%/Backup_on_%d%_%t%.json
}
catch
{
python dtz/manage.py dumpdata>> %pathName%/Backup_on_%d%_%t%.json
}
pause
xcopy dtz\templates\media %pathName%\media /s
Error i am getting CommandError: Unknown app in excludes: contenttype
Please help me out.
There are no try-catch blocks in batch scripts. You need to use the errorlevel returned by a command to check whether it executed successfully or failed. Generally errorlevel 0 indicates that the command executed successfully, but the errorlevel can also depend on the command/program being executed.
Details about ERRORLEVEL.
ERRORLEVEL can be used as follows:
IF %ERRORLEVEL% NEQ 0 (do something)

batch file to check existance of directory if not exists then use alternate directory for file copy

I am trying to write a batch file that copies an exe file from a network location to a local location. It currently works but depending on windows version (xp or win7) the user has to select the correct .bat file due to different local paths needed for the copy. (they are going to the startup folder to be ran every time user starts machine). This is the first time i've ever worked with writing batch files and am completely lost when looking at the syntax for if statements. If i could get some help figuring this out it would be great.
Here is what I currently have that works for XP:
REM #ECHO OFF
ECHO STARTING MOVEFILES
SET EXITRC=0
SET EXITMSG=EXITRC INITIALIZED
ECHO %EXITRC% -- %EXITMS
COPY "\\networkDrive\install\Individual\program\MOVEFILES.EXE" "C:\DOCUMENTS AND SETTINGS\ALL USERS\START MENU\PROGRAMS\STARTUP\"
ECHO COPIED FILES TO YOUR PC
SET EXITRC=%ERRORLEVEL%
IF NOT %EXITRC% == 0 GOTO :EXIT
SET EXITMSG=PROCESSING COMPLETE
:EXIT
ECHO STEP: %EXITMSG% RC: %EXITRC%
ECHO FINISHING MOVEFILES
PAUSE
EXIT %EXITRC%
Here is what I have for Windows 7:
#ECHO OFF
ECHO STARTING MOVEFILESWIN7
SET EXITRC=0
SET EXITMSG=EXITRC INITIALIZED
ECHO %EXITRC% -- %EXITMS
COPY "\\networkDrive\install\Individual\program\MOVEFILES.exe" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
ECHO COPIED MOVEFILESWIN7 TO YOUR PC - All Users / Public Startup folder
SET EXITRC=%ERRORLEVEL%
IF NOT %EXITRC% == 0 GOTO :EXIT
SET EXITMSG=PROCESSING COMPLETE
:EXIT
ECHO STEP: %EXITMSG% RC: %EXITRC%
ECHO FINISHING MOVEFILESWIN7
PAUSE
EXIT %EXITRC%
I would like to have only one batch file that will cover both scenarios so there is no confusion to the user on which batch file to run.
You can utilise the environment variable %ALLUSERSPROFILE%.
On WinXP the default is C:\Documents and Settings\All Users
On Win7/2008 the default is C:\ProgramData
There is a table available here: http://ss64.com/nt/syntax-variables.html
I see you also copy a different file. Not sure why you do that. Maybe you could detect using a method here: https://stackoverflow.com/a/2788764/1553090 -- Otherwise perhaps you should take advantage of the %ProgramFiles% and %ProgramFiles(x86)% variables.
Just to elaborate on how you might choose to use these variables... You can test the Win7 startup folder for existence, and if it's not there just fallback to the XP (regardless of whether it exists).
set STARTUP_WIN7=%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup
set STARTUP_WINXP=%ALLUSERSPROFILE%\Start Menu\Programs\Startup
if EXIST "%STARTUP_WIN7%" (
set STARTUP=%STARTUP_WIN7%
) else (
set STARTUP=%STARTUP_WINXP%
)

Build events in C++ project

I have a post-build event in my C++ Visual Studio 2010 project, which uses command xcopy, but when this xcopy return error code (>0), all build failed too and message "build unsuccessfull", how can i turn of error sensetivity in build events?
Thanks!
You can use the Exec task's IgnoreExitCode:
<Target Name="MyAwesomePostBuildTarget" AfterTargets="Build">
<Exec IgnoreExitCode="true" Command="xcopy etc. etc." />
</Target>
You can override the failure result of (almost) any batch CMD by appending || exit /b 0 to the end of the command. Example:
del somefile.txt || exit /b 0
In this way batch files work a bit like C. You can do && to conditionally run a command when the previous command succeeds, and || to run a command when the previous command fails.
exit /b 0 tells the CMD processor to exit the script and set the errorlevel to zero (0). Never forget to include the /b switch! Without it, CMD will exit the calling script as well as the current script which is rarely, if ever, the desired behavior.
I use this trick from the Visual Studio IDE, so there's no need to do low-level project hacking. And it fits on one line, which is also convenient from the IDE.
Another useful trick is silencing the command, by the way:
xcopy srcfile destfile 1>nul 2>nul || exit /b 0
1 is stdout, and 2 is stderr. Windows suite of shell programs are notoriously inconsistent with regard to which output they might use, so I generally just pipe both or pipe neither.

Windows Batch Commands - Advanced Error Suppression Issue

I'm programming a very large purpose-driven Windows command prompt batch program.
The problem is that I can't suppress the error's text. I could "cls" but that means that almost every command will cls the prompt and I don't want to force that on users. I also tried using >nul after it, and 2>nul in front of the command. The problem with 2>nul CMDOW.EXE /RUN is that then it doesn't store the error in the ERRORLEVEL environment variable.... I also can't have this error info showing up almost every time they use a command in the prompt.
My console does tons of things, including quick navigation and web-page/program/folder access. Recently I have been trying to implement a basic wrapper around the central batch program so that if you type something that is an unrecognized command, it will first check to see if the text string you input is the beginning of a folder's name within your current directory. If so, it will auto-move you into the folder. If not, it will display the usual error message.
I made it so that the input is no longer standard dos input, but a set /p command with a prompt that imitates the usual interface. I got it so it doesn't wait when typing a program name when not preceded by "start" if its in a PATH using CMDOW.
Everything functions now except I have a small issue that's a large visual nuisance. I prompt the user and store the input to an environment variable, then use CMDOW.exe /RUN to first attempt to execute the input text and see if it's an executable file (this covers paths, as well as .exes in the current directory). I then check ERRORLEVEL to see if this resulted in an error. If so, I move on to the next method.
I've also tried writing a little C++ program to execute for me, it works easily with winexec but idk how to obtain error code to confirm the process started sucessfully. If I can do that, then I can just send that result to an environment variable. CreateProcess() doesn't work without being absolute with the location. I can't just plug in the input text and have it work but it pauses until termination anyway I believe. ShellExecute() works but doesn't seem as simple as plugging it in from input... though it appears to have a ready method of obtaining the output. I might add I'm not great at C++, I learn what I need to to get by.
I'm not sure how to get around this issue. I'm also not sure if there exists some special method to bypass that error output while still gaining the knowledge that it didn't execute properly.
Here is my code:
#SETLOCAL ENABLEDELAYEDEXPANSION
#ECHO OFF
#for /L %%i in (0,0,0) do #(
set zinput=
set /p zinput=^%time%[%cd:~0,1%]^>
call :EXECUTE
set zinput=
)
:EXECUTE
IF ("%zinput%")==("") GOTO :EOF
cmdow /run "%zinput%"
set ERRCODE=%ERRORLEVEL%
IF ("%ERRCODE%")==("1") call :UNDEFINED
GOTO :EOF
:UNDEFINED
%zinput%
set ERRCODE=%ERRORLEVEL%
IF %ERRCODE%==9009 GOTO ZDIR
GOTO :EOF
:ZDIR
set zDIR=
DIR /B /AD-H|sed -n "/^%zinput%/"Ip>"%aicnspath%\etc\dump.txt"
set /p zDIR=<"%aicnspath%\etc\dump.txt"
IF NOT DEFINED zDIR GOTO UNDEFINED2
cd %zDIR%
call "%aicnspath%\etc\update.bat"
cls
echo AUTO-MOVED INTO: %CD%|tr '[a-z]' '[A-Z]'|sed "s/^/%_hc%%_bc2%/"|sed "s/$/%_bc%/"
echo -----------------------------------------
echo/
GOTO :EOF
:UNDEFINED2
cls
echo/
echo The string %_hc%%_bc2%^'%zinput%^'%_bc% is not recognized by AICNS as any internal or external command, operable program or batch file.
echo/
GOTO :EOF
Try this...
CMDOW /run "%zinput%" >nul 2>&1
You should still have access to the ERRORLEVEL after this.
I don't see any reason because 2>nul CMDOW.EXE /RUN don't return the ErrorLevel value whereas CMDOW.EXE /RUN return it, unless CMDOW.EXE was written this way; this sound very strange to me.
The Batch file below check if a command is an executable file and return these values via ErrorLevel: 0 if not found, 1 if found in current directory, and 2 if found in a directory of PATH variable. I hope you can use a modified version of this Batch file instead of CMDOW.EXE program to solve your problem.
PATHOF.BAT:
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM CREATE A LIST OF FILE NAMES ADDING THE EXECUTABLE EXTENSIONS
SET NAMEEXT=!PATHEXT:.=%1.!
REM SEARCHES FILE NAMES IN CURRENT DIRECTORY, IF FOUND: ERRORLEVEL=1
FOR %%N IN (%NAMEEXT%) DO IF EXIST %%N ECHO %%N & EXIT /B 1
REM SEARCHES FILE NAMES IN DIRECTORIES OF PATH VARIABLE, IF FOUND: ERRORLEVEL=2
FOR %%N IN (%NAMEEXT%) DO IF NOT "%%~$PATH:N" == "" ECHO %%~$PATH:N & EXIT /B 2
REM IF FILE NOT FOUND, ERRORLEVEL=0
ECHO '%1' is not an external command or batch file located in PATH & EXIT /B 0
Please, let me know if this method worked or if you got an additional problem using it.