Execute Command stage

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Execute Command stage

Post by Javieregh »

Hi

I'm using in Execute Command stage to call a DOS batch script that in turn runs .bat, my parameters is:

Command: @
Parameters: "#seq_path#\#APORIProcessDeleteFile#" ( \\filedev\ETLDataFiles\Devl\DM\XXX\Test1\deletefile.bat )


But I have trouble because it does not make the call to the script: the contents of the bat is as follows:
(Delete files with more than 6 months)

@echo off
setlocal
set cutOff=%~2
set workDir=%~1
if "%1"=="" set workDir=.
if not "%cutOff%"=="" goto START

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
set mm=%%a
set dd=%%b
set yyyy=%%c
)

set /a mm=1%mm% -6 - 101
if /i %mm% LSS 1 set /a mm=12&set /a yyyy-=1
if /i %mm% LSS 10 set mm=0%mm%
set cutOff=%yyyy%%mm%%dd%

:START
pushd.
cd /D "%workDir%"

for /f "delims=" %%a in ('dir /b /a-d 2^>NUL') do if /i "%%a" NEQ "%0" call :PROCESS "%%a" %%~ta

popd
goto :EOF
:PROCESS

for /f "tokens=1-3 delims=/" %%a in ('echo %2') do (
set cmm=%%a
set cdd=%%b
set cyyyy=%%c
)

if /i "%cyyyy%%cmm%%cdd%" LEQ "%cutOff%" del %1

Thanks advanced.
Javier
Consultant in DTS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't think "@" (no echo) will work as the command. With everything parameterized it typically is a "shell" command so perhaps "cmd" would work for Windows there? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Post by Javieregh »

chulett wrote:I don't think "@" (no echo) will work as the command. With everything parameterized it typically is a "shell" command so perhaps "cmd" would work for Windows there? :? ...
I change it to CMD, stays in DataStage directory and does not change the directory LAN

Output from command ====>
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\DSProjects\DEVL_DM>
Consultant in DTS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No idea what to try next. Worst case, write a routine to use DSExecute( ) and run with a Routine Activity stage instead.
-craig

"You can never have too many knives" -- Logan Nine Fingers
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

It looks like both your pushd. and popd are not working. Put a test statement after the cd /D "%workDir%" to make sure your "cd" to that directory is successful. Don't just assume it's in the specified directory.
jguerrero
Participant
Posts: 21
Joined: Wed Aug 27, 2003 5:12 pm
Location: Chile -South America
Contact:

Post by jguerrero »

Hi,

Do you try to use:

Command:#seq_path#\#APORIProcessDeleteFile#
Parameter: (what you need inside the script)
Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Post by Javieregh »

lstsaur wrote:It looks like both your pushd. and popd are not working. Put a test statement after the cd /D "%workDir%" to make sure your "cd" to that directory is successful. Don't just assume it's in the specified directory.
The dslog is:
Output from command ====>
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\DSProjects\DEVL_DM>

and should be "\filedev\XXX\XXX\ISB\Standing\ETLDataFiles\Test1"
Consultant in DTS
Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Post by Javieregh »

jguerrero wrote:Hi,

Do you try to use:

Command:#seq_path#\#APORIProcessDeleteFile#
Parameter: (what you need inside the script)
Command: cmd
Parameters: "#seq_path#\#APORIProcessDeleteFile#"

#seq_path# = \\filedev\ETLDataFiles\Devl\DM\XXX\Test1\
#APORIProcessDeleteFile# = deletefile.bat
Consultant in DTS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

jguerrero wrote:Do you try to use:

Command:#seq_path#\#APORIProcessDeleteFile#
Parameter: (what you need inside the script)
You can't because no parameter substitution is done in the Command box.
-craig

"You can never have too many knives" -- Logan Nine Fingers
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

Try the following:

Command: START
Parameters: #seq_path# #APORIProcessDeleteFile#

#seq_path# = \\filedev\ETLDataFiles\Devl\DM\XXX\Test1\
#APORIProcessDeleteFile# = deletefile.bat
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Wow. My DOS memories are cautiously raising their heads from the depths I banished them to years ago. Start, pushd, popd... expanded memory, extended memory... ah, those were the days. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Post by Javieregh »

lstsaur wrote:Try the following:

Command: START
Parameters: #seq_path# #APORIProcessDeleteFile#

#seq_path# = \\filedev\ETLDataFiles\Devl\DM\XXX\Test1\
#APORIProcessDeleteFile# = deletefile.bat
did nothing, I think the problem is not changing the directory by default DataStage
Consultant in DTS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You have no idea and the pushd/popd mask things. Why not comment out the "@echo off" for now and see what it logs?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Javieregh
Participant
Posts: 25
Joined: Mon Apr 16, 2007 10:35 am
Location: JavierGH

Post by Javieregh »

chulett wrote:You have no idea and the pushd/popd mask things. Why not comment out the "@echo off" for now and see what it logs? ...
I put the @echo off in comment and it didn't work, I am obtaining this when I run log:

The dslog is:
Output from command ====>
C:\DSProjects\DEVL_DM>
(this one is the Datastage directory)

and I'm expecting to be in this directory "\filedev\XXX\XXX\ISB\Standing\ETLDataFiles\Test1"

I'm using in Execute Command stage and my parameters are:
Command: START
Parameters: #seq_path# #APORIProcessDeleteFile#
#seq_path# = \\filedev\ETLDataFiles\Devl\DM\XXX\Test1\
#APORIProcessDeleteFile# = deletefile.bat

Do you have any script or any suggestion to change directories.

Thank you for your help
Consultant in DTS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What do you mean it "didn't work"? :? Removing it should allow everything written to 'the screen' to be captured in the log. It wasn't meant to fix anything but rather give you an idea what needed to be fixed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply