Options

Start a *.bat file - procedure

n.topalovn.topalov Member Posts: 26
Hi all, I know that there a lot of topics about similar kind of issues but I did no find a solution to myself.

So my problem is the following: I want to start an outside *.bat file which opens a cmd screen and start a procedure that takes about 6-7 sec. So when I start this file from Navision using SHELL - it actually run the file but didn't wait it to finish with the procedure and close the cmd screen immediately and nothing actually happen.

I tried several ways of starting SHELL (full path, short path), use a SLEEP after the SHELL but no success.

Please can you help me with this issue.

P.S. I am using SQL database with Navision 5.01 client

Thank you!

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,098
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    n.topalovn.topalov Member Posts: 26
    Thanks for the reply but still do not get the wanted result.

    I tried every type of the showing the screen but still as soon as press the button( from where I start DosShell) the screen appear for a second and then dissapear with nothing done.
  • Options
    ufukufuk Member Posts: 514
    What happens when you run the bat file directly? Does DOS shell disappear immediately again or this problem emerges only when running from Navision?
    Have you tried running another bat file from Navision?

    You can also try adding a Pause command to the last line of the bat file. This way it will wait until you press a key to finish the process.
    Ufuk Asci
    Pargesoft
  • Options
    n.topalovn.topalov Member Posts: 26
    Thank you all. I just found the solution.

    Yes when I ran the bat file it all goes well but when I start it from Navision it don't do anything.

    But this paused that you tell me to put let me find the reason for the problem. It was in the bat file. It starts another .exe and the problem was that in the directory of the .exe in the bat file a 'cd' was missing and it couln't find it, and when I start it from Navisoion there was a problem. Nevermind.

    Thank you
  • Options
    mabl4367mabl4367 Member Posts: 143
    If you use the "Run" methode of an automation variable of type 'Windows Script Host Object Model'.WshShell you can hide the command prompt window and make it wait untill the command has been executed.
  • Options
    n.topalovn.topalov Member Posts: 26
    yeah I can know made a lit bit more userfriendly - hide the window, and use the return value to show status to the user.

    Thanks
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    The following code might be useful...
    Function is called RunShellFunction(pCommandLine Text 1024)
    
    Code inside function is;
    
    IF STRPOS ( ApplicationManagement.ApplicationVersion , '3.70' ) <> 0 THEN
      SHELL ( pCommandLine )
    ELSE BEGIN
      CREATE(WSH);
      WSH.Run(pCommandLine);
      CLEAR(WSH);
    END;
    
    

    WSH is an Automation variable of type 'Windows Script Host Object Model'.WshShell

    The RUN method allows you to change parameters for WindowStyle and WaitOnReturn.
  • Options
    aniruddha_majumdaraniruddha_majumdar Member Posts: 57
    Hi All,

    I am trying to run a batch file from MSD NAV using 'Windows Script Host Object Model'.WshShell (based on Kirki's function)variable but in vain.

    The command is as follows

    RetournValueAsInteger := DosShell('C:\abc.bat',1,TRUE);

    Please help me to resolve the problem.

    Regards,
    Ani
    Thanks & Regards,
    Aniruddha
  • Options
    AdrianAkersAdrianAkers Member Posts: 137
    Do you get an error message?

    Why are you not calling Run or Exec?
Sign In or Register to comment.