Page 1 of 1

Running batch file from DS job

Posted: Sun Dec 10, 2006 8:44 pm
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

Posted: Sun Dec 10, 2006 10:14 pm
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.

Posted: Sun Dec 10, 2006 10:26 pm
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\".

Posted: Sun Dec 10, 2006 11:13 pm
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.

Posted: Sun Dec 10, 2006 11:52 pm
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.

Posted: Sun Dec 10, 2006 11:58 pm
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

Posted: Mon Dec 11, 2006 12:36 am
by khaled007sg
I echoed errorlevel and the output is 0. and i tried quoting the path names also but i did not work. :cry:

Posted: Mon Dec 11, 2006 3:02 am
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:

Posted: Mon Dec 11, 2006 9:16 am
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.

Posted: Mon Dec 11, 2006 7:34 pm
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:

Posted: Mon Dec 11, 2006 9:17 pm
by chulett
Ya folks, don't be shy! Jump on in with your thoughts and/or suggestions. :wink:

Posted: Mon Dec 11, 2006 9:53 pm
by kduke
I got an idea, XCOPY sucks. You found a bug.