Trying to run a Batch file (.bat) in Opentext MBPM 9.2

Options

Good Afternoon All,

 

I am currently working to create a mechanism my users can use that will run a windows batch file (.bat).

 

I have searched around and found a few C# Scripts that purport to show how to do this, so I have created code activity object and attempted to use the script I have found to run several variations on the following:

 

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "D:\\bin\\Test.bat";
process.StartInfo = startInfo;
process.Start();

The script validate function returns no issues, and I can deploy the solution with no errors.  When I Click the command button that results in the script execution, again there is no error.

I have attempted to run the debugger, but it doesn't really give me a helpful result (it basically says "you wrote it, you fix it")

We have the installation on separate servers for the three tiers (Web, Engine, DB).  The batch file resides on the Engine Server. Should it be on the Web Server?

I'm afraid I am a newbie with MBPM 9.2 and also to C#.  Does anyone have a suggestion on something I may be doing wrong or on a different way to approach the problem?

 

Tagged:

Comments

  • Anything server side (so any C# in proceses) should be on the Engine server.

    At a glance your code makes sense but I might suggest trying it in Visual Studio first to confirm it does what you expect.


  • Jeastman wrote:

    At a glance your code makes sense but I might suggest trying it in Visual Studio first to confirm it does what you expect.


    That may just be a suggestion, but I dio read this a lot. It implies that you expect your customers all to have Visual Studio installed. To my mind, that takes away much of the attractiveness of using a tool such as MBPM.

  • Hi Scott,

     

    Try adding the command "/c" parameter before your argument like below and see if that helps.

     

    startInfo.Arguments = "/c D:\\bin\\Test.bat";

     

    Also, you could try adding the following to the end of your code to see what exit code the process is producing for debugging purposes, writing it to eLog for inspection:

     

    var processInfo = Process.Start();

    processInfo.WaitForExit();

    Mstm.WriteToLog("Exit Code = " + processInfo.ExitCode,"",Severity.Information);

     

     

    Hope this helps, but if you need some further information on this subject check out some posts on StackOverflow. e. g(http://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp)

     

     

    If you do happen to have Visual Studio installed, you could probably test this out really quickly with a little C# console app rather than pushing it through the engine.

     

    All the best.

  • The code looks okay although it shouldn't be needed to shell through cmd.exe. You can just set startInfo.FileName = @D:\bin\Test.bat and set no args (or set the filename to cmd.exe + [space] + "path"... ie, pass the arg inline). If your path has a space in it then it needs to be wrapped in double quotes. I would not suggest calling WaitForExit() in production as this would block the engine thread (although it's a good idea for debugging). Also, keep in mind, that server scripts run on the engine, in the context of the engine account so any network resources you access should be accessible by the engine account.

  • Hi Phil,

     

    Thank you for the Suggestions.  Adding /c seems to have no effect.  I did add the bit to write the exit code to elog.  it returns Exit Code =1 each attempt.  I believe this is "incorrect Function" but my Google-Fu may be failing me

  • Hey Tony,

     

    Thanks for the input.  I'm afraid these suggestions do not work. The bat file I am creating is Saved Locally on the engine server and I have given the Engine process Full controlover the directory.

  • Phil,

     

    Thank you for the link to the stack overflow thread.  I am working my way through it, but nothing in there seems to be working either.

     

     

  • Is "D" just how you have the server's drive mapped on your local? Try using the actual server share's name instead like '\\MyServer\whatever'... that should work anywhere that has access. Also, 'bin' is a scary folder to be running out of... there could be a permissions issue if this is where a running application's source dlls/resources reside.

  • Regarding permission issues, I've found Process Monitor to be a great tool for debugging these sorts of issues not just in BPM but in Windows applications in general:

     

    http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

     

    For your use, I'd scope the filter down to just include the PATH = D:/your/path/to/batch.bat

     

    If you are running into a file permission error, not only will it tell you where but what account is trying to access it.

     

    However, as Tony mentioned /bin might be some protected name. I've seen UAC do some weird things and Process Monitor doesn't catch them beyond telling you it failed.

  • Hi Scott

     

    I need to run a batch file from metastorm and was wondering if you had any success in doing this?

     

    Brian