How to Execute a .BAT File

Hi,

Please guide me as how to Execute a .BAT file in DI. The tool is installed on Windows 2003.
This BAT file fetches two files from a diiferent server.

This is the format of the script which i wrote in a script file

“exec(‘cmd’, ‘E:\Subsidiary\Sub.bat’, 4);”

This job is completing successfuly, but I am not getting any files in the Required folders.

If I execute the BAT file manually it is returning the Files.

Please Guide

Thanks In advance

-Sherry-


sherry :india: (BOB member since 2007-01-31)

Sherry,

Because .bat files are executable, I call all of my bat files as so:


exec('E:\\Subsidiary\\Sub.bat', '', 4);

Oh, and I think because the third parameter in exec() is a “4” DI is not raising an exception and, thus, allowing the job to complete successfully regardless of whether the bat file completed successfully.


axelrod_eric :us: (BOB member since 2007-11-10)

Hi Eric,

Thanks for the reply.

I tried the script as you had shown, Still the Job completed succesfully, but the the files were not copied.

This BAT file copies two files from a different sever, so should I change the flag values?

Please Advice.

Best Regards,

-Sherry-


sherry :india: (BOB member since 2007-01-31)

Changing the flag to 0 is worth a try. It will raise a system exception, but it may not be obvious what the problem with the bat.

Why not try calling the copy command directly from DI like so:


exec('cmd','copy ... ' )

And, I forgot to ask, but are you referencing a drive letter or a UNC path for the network location?[/code]


axelrod_eric :us: (BOB member since 2007-11-10)

Hi Eric,

Thank You for the Reply.

I tried with 0 still no exceptions. Job got completed without copying the files.

I am pasting the Contents of the file here

echo off
net use t: \htsapps065\Subsidiary
xcopy /y /e t: e:\subsidiary
echo copy complete
net use t: /delete
echo on

Where “Subsidiary” is a shared folder in the server htsapps065.

Also can you explain the code with “copy” inside the exec.

Best Regards,

-Sherry-


sherry :india: (BOB member since 2007-01-31)

When you logged in to execute the batch file, did you log in as the same user that the job server runs under?

  • Ernie

eepjr24 :us: (BOB member since 2005-09-16)

Hi Ernie,

Yes, I mainly work on the server (in which DI is Installed) itself. With the same login only I manually Executed the Batch file and Executed the Script in DI.

ThanK You for the Reply.
Best Regards

-Sherry-


sherry :india: (BOB member since 2007-01-31)

Okay, next step. Have you assigned the result of the EXEC to a variable and printed it? It should say "copy complete ", since that is what you echo in the script.

  • Ernie

eepjr24 :us: (BOB member since 2005-09-16)

Hi,

No I have not. How should I do that?

ThanK You for the Reply.
Best Regards

-Sherry-

[/img]


sherry :india: (BOB member since 2007-01-31)

Here is a snippet of our standard execute block. It will be a bit different from yours, since we are Linux, but close.


$N_Dir_Base_Glob = '/home/scripts/projectname/';

# Run the script and raise an exception if error is returned.
$I_Exec_Reslt = exec($N_Dir_Base_Glob || 'ScriptName.sh', '', 8);
print($I_Exec_Reslt);

$I_Retr_Code = substr($I_Exec_Reslt, 1, 7);
if ($I_Retr_Code != '      0')
begin
   raise_exception(substr($I_Exec_Reslt, 9, 1020));
end
  • Ernie

eepjr24 :us: (BOB member since 2005-09-16)

Hi Ernie,

I think I am doing the same , but i have not prtinted any variables.
But does that change anyhting, as no eceptions are raised.

I will try this and reply to you.

Thank You
Best Rregards

-Sherry-


sherry :india: (BOB member since 2007-01-31)

Hi Ernie,

I am getting 0 as the result of the Print Function

Thank You
Best Rregards

-Sherry-


sherry :india: (BOB member since 2007-01-31)

Only ‘0’? Not the text you echo?

Does that change if you remove the echo off?

  • Ernie

eepjr24 :us: (BOB member since 2005-09-16)

Hi Ernie,

I am attaching the Code and The trace log.

Please advice me if anything Is wrong

Thank You
Best Rregards

-Sherry-
Attachment.doc (49.0 KB)


sherry :india: (BOB member since 2007-01-31)

Hi Ernie,

Can You please provide me with a solution for this…??

Should I Edit the Code in the BAT file? The code is provided in one of the Replies I have posted above .

Thank You
Best Rregards

-Sherry


sherry :india: (BOB member since 2007-01-31)

Sorry, Sherry, I am out of options for you on this one. I would open a ticket with support or see if anyone else here who is on Windows can chime in with some ideas.

  • E

eepjr24 :us: (BOB member since 2005-09-16)

Hi Ernie,

Thanks a lot for the help. IF i manage to find some solution, I will update it here.

Best Regards,
-Sherry-


sherry :india: (BOB member since 2007-01-31)

I may be entirely wrong here, but I thought it was not possible for a service to map drives, the net use command when run in the job via the service is unlikely to work. As I say, I could be wrong.

Can you make it a permanently mapped drive for that user and see if it makes any odds?


HuwD :uk: (BOB member since 2007-04-19)