Running batch file from DS job

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

Moderators: chulett, rschirm, roy

Post Reply
khaled007sg
Participant
Posts: 5
Joined: Sun Dec 10, 2006 8:33 pm

Running batch file from DS job

Post by khaled007sg »

I have a ms-dos batch file to be called from Datastage server job. the batch file takes 3 arguments. the file looks like this...

Code: Select all

@ECHO OFF
:parameter 1- Backup Dir
:parameter 2- Hash dir
:parameter 3- Sequential dir


:Echo this is batch file

@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( 
	Set Month=%%A
	Set Day=%%B
	Set Year=%%C
)
set hashbackpath= %1\\%Day%-%Month%-%Year%\\Hashed
set seqbackpath= %1\\%Day%-%Month%-%Year%\\Sequential\\Output

md %hashbackpath%
xcopy %2\*.* %hashbackpath% /e /y

md %seqbackpath%
xcopy %3\Output\*.* %seqbackpath% /e /y

PAUSE

When i run the script from the command prompt it works fine but when i call it from the job it only creates the folders but it doesn't copy anything to the folders.

Anyone can help? Thanks in advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Welcome aboard. :D

How are you calling it 'from a job'?

Are you passing in fully qualified paths for each directory?

What happens if you comment out the '@ECHO OFF' and capture the screen output into you job's log? That may help figure out what is going on. However, the most common problem is the use of relative paths in scripts called from DataStage jobs.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khaled007sg
Participant
Posts: 5
Joined: Sun Dec 10, 2006 8:33 pm

Post by khaled007sg »

Hi chulett
thanks for the reply. I m calling it from Execute command Activity. Even if i comment out @echo off it doesnt display anything in the log.

Code: Select all

Untitled2..JobControl (@Execute_Command_0): Executed: D:\test.bat D:\MyOutput  D:\source\Hash  D:\source\Seq
Reply=0
Output from command ====>

I have tested with another batch file to check wheather the parameters r passed. and it is passed. I m using the full path e.g "D:\MyTest\MyOutput\".
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Those xcopy commands certainly should echo out what they are doing and be captured in the log. :? What exactly do you have in the Command and Parameter options inside the Command Activity stage?

I don't see anything obvious. Perhaps some bread crumbs would help... add echo statements at key points, in particular echo out the value of the %hashbackpath% and %seqbackpath% variables after you set them, then check the log again.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khaled007sg
Participant
Posts: 5
Joined: Sun Dec 10, 2006 8:33 pm

Post by khaled007sg »

in Command Activity Stage i have

Command-->D:\test.bat
Parameters-> (3 parameters) D:\MyOutput D:\source\Hash D:\source\Sequential\


After echo out the value of the %hashbackpath% and %seqbackpath%
I got

Code: Select all

Untitled2..JobControl (@Execute_Command_0): Executed: D:\test.bat D:\MyOutput  D:\source\Hash  D:\source\Seq
Reply=0
Output from command ====>
 D:\MyOutput\11-12-2006\Hashed
 D:\MyOutput\11-12-2006\Sequential\Output
Everything is fine except the xcopy doesn't seem like working. It works fine in the command promt though.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Can you include a test for %ERRORLEVEL% in the BAT file, and maybe pass control to some code that displays the actual command at that point.

Perhaps you could also try quoting the pathnames.
For example xcopy "%2"\*.* "%hashbackpath%" /e /y
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
khaled007sg
Participant
Posts: 5
Joined: Sun Dec 10, 2006 8:33 pm

Post by khaled007sg »

I echoed errorlevel and the output is 0. and i tried quoting the path names also but i did not work. :cry:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Just checked the help on XCOPY. Maybe you need a /D switch?
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
Yes, I'm running out of ideas, and clutching at straws. :cry:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

In other words, we've done what we can do sitting on the other side of your monitor. Now it's time to find someone on the same side of the glass as you and get another pair of eyes involved. :wink:

Hopefully someone DOS batch savvy.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khaled007sg
Participant
Posts: 5
Joined: Sun Dec 10, 2006 8:33 pm

Post by khaled007sg »

Hi Ray
I have used the /d switch but the same thing. :( . I like to thank both u and craig for trying. I m really lost at the moment :cry: . The "copy" command works, the "move" command also works only the "xcopy" aint working. But copy and move command are not what i need. what i need to do is copy all the subfolders in a folder.

I have also written a c++ program which calls that batch file with parameters and i try to call the exe file from the Command Activity Stage, but still the same thing.

Someone plzz helpppppp :cry:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ya folks, don't be shy! Jump on in with your thoughts and/or suggestions. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

I got an idea, XCOPY sucks. You found a bug.
Mamu Kim
Post Reply