2 Replies Latest reply: May 15, 2014 10:09 AM by Bill Watson RSS

    PreProcess Script Runs in Test but not in Process

    Jim Weeks

      Hello,

      I am trying to run a PreProcess script for the first time in MDP 10.5.  The script is a .bat file located on a mapped drive (for which I have put in the entire path) When I run it in test, it returns "True".  But when the process itself runs, the PreProces script does NOT run.  Any ideas welcome!

       

      Thanks in advance!

       

      Jim Weeks

        • PreProcess Script Runs in Test but not in Process
          Gareth Horton

          Hi Jim,

           

          Sorry for the delay - it's quite a trick issue.

           

          There are a some layered problems here:

           

          1. Windows services do not have access to mapped drives (unless running as LocalSystem with the Interact With Desktop setting enabled)

          2. Windows services do not have acces to the shell / command interpreter (i.e you can't just execute a file with a .bat extension)

          3. The command interpreter cannot address UNC paths

           

          The first issue to address is 2 - you need to call CMD.EXE explicitly to execute the batch file - so your PreProcess script would look like this:

           

          If Shell("""C:\Windows\SysWow64\cmd.exe"""" "Log.ExpandMacros("/C ""c:\temp\test.bat"""),AppWinStyle.Hide,True,20000) <> 0 Then

            ' TODO: Handle command timeout here.

          End If

           

          Note that I have a 64-bit machine, but am using the 32-bit command interpreter, for compatibility.  Also, I'm using the /C argument for CMD.EXE to ensure that the process returns after execution so MDP doesn't timeout and produce a failure.

           

          You may notice that I am using a batch file on a local drive, which is not what you needed to do.

           

          This is solving 1 and 3.

           

          This batch file is a kind of link to the real batch file and needs to look like this:

           

          pushd
          server\folder_containing_batch_file

          do_the_real_work.bat

          popd

           

          This will create a temporary mapping to the UNC folder containing the remote batch file, execute the remote batch file, then remove the temporary mapping.

           

          I hope this works for you - I tested it successfully myself.

           

          Best regards

           

          Gareth

           

          If Shell("""C:\Windows\SysWow64\cmd.exe"""" "Log.ExpandMacros("/C ""c:\temp\test.bat"""),AppWinStyle.Hide,True,20000) <> 0 Then

            ' TODO: Handle command timeout here.

          End If

           

          pushd "
          horton810\work"

          test.bat

          popd

           

          Hello,

          I am trying to run a PreProcess script for the first time in MDP 10.5.  The script is a .bat file located on a mapped drive (for which I have put in the entire path) When I run it in test, it returns "True".  But when the process itself runs, the PreProces script does NOT run.  Any ideas welcome!

           

          Thanks in advance!

           

          Jim Weeks[/QUOTE]

            • PreProcess Script Runs in Test but not in Process
              Bill Watson

              that is a pretty nifty solution there Gareth. I have run into the situation in the past where a batch file won't run and this may be a viable alternative to the solution we put in place. We do however tend to use the full UNC path whenever we are doing anything in datapump - it just seems to behave much better and of course keeps us consistent in terms of maintaining paths within Monarch models and projects used by datapump.

               

              so instead of having

               

              if Shell("""Z:[URL="file://
              BATCH\SOMEBATCH.BAT""",AppWinStyle.Hide,True"]\DATADUMP\PROCS\BATCH\SOMEBATCH.BAT""",AppWinStyle.Hide,True[/URL]) <> 0 then

              log.addevent("Postprocess Batch NOT run")

              return false

              else

              log.addevent("Postprocess Batch run")

              end if

              /code

               

              we would have

               

              if Shell("""[URL="file://
              SOMESERVER\SOMESFOLDER\DATADUMP\PROCS\BATCH\SOMEBATCH.BAT""",AppWinStyle.Hide,True"]
              SOMESERVER\SOMESFOLDER\DATADUMP\PROCS\BATCH\SOMEBATCH.BAT""",AppWinStyle.Hide,True[/URL]) <> 0 then

              log.addevent("Postprocess Batch NOT run")

              return false

              else

              log.addevent("Postprocess Batch run")

              end if

              /code