DOS Access from Navision

chiramelchiramel Member Posts: 23
Is it Possible to run one command in DOS from navision?
regards
febin
Febin Chiramel
Mumbai
India

Comments

  • Arjan_SomersArjan_Somers Member Posts: 64
    See the SHELL command in the C/AL manual
  • chiramelchiramel Member Posts: 23
    how to pass one caommand into dos by using shell


    any body can give some examples or related links
    Febin Chiramel
    Mumbai
    India
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from Navision DOS forum to Navision forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • garakgarak Member Posts: 3,263
    use shell() or WSH.

    Which command do you will send to DOS :?:
    Do you make it right, it works too!
  • chiramelchiramel Member Posts: 23
    I want to simply run Command prompt and pass DIR command.

    Thanks
    Febin Chiramel
    Mumbai
    India
  • PoltergeistPoltergeist Member Posts: 200
    Something like SHELL(ENVIRON('comspec'), ' /c dir *.* > file.txt')
  • chiramelchiramel Member Posts: 23
    Its not working yaar
    Febin Chiramel
    Mumbai
    India
  • PoltergeistPoltergeist Member Posts: 200
    What's not working? do you see any messages. Replace /c with /k to see what happens...
  • chiramelchiramel Member Posts: 23
    ya now it is working ..
    But its default path i'm seeing is licence file path......
    where this path is storing ....
    Do you have any Idea...
    Febin Chiramel
    Mumbai
    India
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Please be more specific on what you need to accomplish by pass DOS command. You mentioned in the previous post that you only need to pass DIR command, but now, you want something different? :?:
  • PoltergeistPoltergeist Member Posts: 200
    chiramel: first take a look how the command prompt works. If you want to write the contents of a directory to a file, you need to redirect it. Hence the '> file.txt. ' If you want to redirect it to a certain file in a certain directory, use '> <driveletter><pathname><filename>. For example, '> c:\test\output.txt' would redirect the output of the dircommand to the file output.txt, in the directory test, on de C: drive.

    If you do not want the output to be written in a file, simply omit the '> file.txt' part.

    If you want a specific directory to be listed, you need to change the dir command, like dir <driveletter><pathname><filename>, like dir c:\program files\*.* would list all the files in the directory program files on the c: drive.

    If you got everything working, change the /k back to /c, so it will continue automatically.

    If you want to test things first, start the commandprompt, and try the commands there, without the 'SHELL(ENVIRON('comspec'), ' /c' part


    One more example: To get a listing of the complete windows directory of the computer, from navision, and get it in the file 'navoutput.txt' in the temporary directory, the command would be:

    SHELL(ENVIRON('comspec'), ' /c dir %Windir%\*.* /s > %temp%\navoutput.txt')

    Or, in more readable form (but less flexible)

    SHELL(ENVIRON('comspec'), ' /c dir c:\windows\*.* /s > c:\docume~1\chiramel\locals~1\temp\navoutput.txt')


    All in all, you need to take a look into the DIR command of the commandprompt. So start the commandprompt and type dir /?
  • strykstryk Member Posts: 645
    Hi!

    I would also recommend to use the "Windows Script Host" instead of SHELL, as it provides more smart features; e.g. like hiding the DOS-Box and avoiding the "Trusted-Confirmation-Dialog" (since NAV 4.00).

    Here an example:
    {Variables: 
    WSH_Shell     Automation 'Windows Script Host Object Model'.WshShell 
    Command       Text255 
    ExitCode      Integer 
    WindowStyle   Variant 
    WaitOnReturn  Variant} 
    
    Command := STRSUBSTNO('%1 /c dir *.* > file.txt', ENVIRON('COMSPEC'));  // set DOS-Command here
    
    WindowStyle := 0; 
    
    { Window Styles: 
    0 Hide the window and activate another window. 
    1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time. 
    2 Activate & minimize. 
    3 Activate & maximize. 
    4 Restore. The active window remains active. 
    5 Activate & Restore. 
    6 Minimize & activate the next top-level window in the Z order. 
    7 Minimize. The active window remains active. 
    8 Display the window in its current state. The active window remains active. 
    9 Restore & Activate. Specify this flag when restoring a minimized window. 
    10 Sets the show-state based on the state of the program that started the application.} 
    
    WaitOnReturn := TRUE;  // modal run, receive ExitCode 
    
    IF ISCLEAR(WSH_Shell) THEN 
      CREATE(WSH_Shell); 
    ExitCode := WSH_Shell.Run(Command, WindowStyle, WaitOnReturn); 
    
    MESSAGE('%1', ExitCode);   // 0 = OK; 1 := Error
    
    Jörg A. Stryk (MVP - Dynamics NAV)
    NAV/SQL Performance Optimization & Troubleshooting
    STRYK System Improvement
    The Blog - The Book - The Tool
  • krikikriki Member, Moderator Posts: 9,112
    http://www.mibuso.com/forum/viewtopic.php?t=12417 :whistle:

    stryk wrote:
    Hi!

    I would also recommend to use the "Windows Script Host" instead of SHELL, as it provides more smart features; e.g. like hiding the DOS-Box and avoiding the "Trusted-Confirmation-Dialog" (since NAV 4.00).

    Here an example:
    {Variables: 
    WSH_Shell     Automation 'Windows Script Host Object Model'.WshShell 
    Command       Text255 
    ExitCode      Integer 
    WindowStyle   Variant 
    WaitOnReturn  Variant} 
    
    Command := STRSUBSTNO('%1 /c dir *.* > file.txt', ENVIRON('COMSPEC'));  // set DOS-Command here
    
    WindowStyle := 0; 
    
    { Window Styles: 
    0 Hide the window and activate another window. 
    1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time. 
    2 Activate & minimize. 
    3 Activate & maximize. 
    4 Restore. The active window remains active. 
    5 Activate & Restore. 
    6 Minimize & activate the next top-level window in the Z order. 
    7 Minimize. The active window remains active. 
    8 Display the window in its current state. The active window remains active. 
    9 Restore & Activate. Specify this flag when restoring a minimized window. 
    10 Sets the show-state based on the state of the program that started the application.} 
    
    WaitOnReturn := TRUE;  // modal run, receive ExitCode 
    
    IF ISCLEAR(WSH_Shell) THEN 
      CREATE(WSH_Shell); 
    ExitCode := WSH_Shell.Run(Command, WindowStyle, WaitOnReturn); 
    
    MESSAGE('%1', ExitCode);   // 0 = OK; 1 := Error
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • strykstryk Member Posts: 645
    :lol:
    Jörg A. Stryk (MVP - Dynamics NAV)
    NAV/SQL Performance Optimization & Troubleshooting
    STRYK System Improvement
    The Blog - The Book - The Tool
  • roylroyl Member Posts: 4
    Is it possible to get a return value from "Shell" command so You know if there were any files in the directory?
    Ex.


    "Sökväg Reklamationer":="Sökväg Reklamationer" + '\' +"No.";
    TESTFIELD("Sökväg Reklamationer");
    SHELL('C:\Windows\explorer.exe',"Sökväg Reklamationer");

    ("Sökväg Reklamationer" = \\ms\rekl)
  • PoltergeistPoltergeist Member Posts: 200
    I don't think so. Perhaps running shell in modal (with a=shell(etc...)) could work, but you probably have to give back an errorlevel. What you could do is (again) use a shell (or wsh.shell) to call a dos command, parse the output to a file, and read that file to get the number of files.


    shell(environ('comspec'),'/c dir /b /s /A-d c:\temp | find "" /v /n /c > c:\temp\file.txt');

    will give you the number of files (not directories) of the c:\temp directory and all subdirectories. If you only want to have the number of files in the c:\temp directory, remove the /s.

    Then read the file from NAV, and you're good to go...
  • ta5ta5 Member Posts: 1,164
    Why not use the virtual file table in nav? :-k
    Regards
    Thomas
  • manjusreemanjusree Member Posts: 79
    Hi,

    I am trying to copy testfile1 using below command:-


    SHELL(ENVIRON('comspec'), 'cd /d d:\nav\'+' & '+' copy testfile1 \\10.7.7.86\nav'+' & '+' del testfile1');

    But system says file is not found :(...Can anyone help me?

    Regards,
    Manjusree
  • PoltergeistPoltergeist Member Posts: 200
    It seems you don't want to copy the file, but move it. Also, you want to to change dirs, and copy from that. The DOScommand should be (or could be)

    Move d:\nav\testfile1 \\10.7.7.86\nav

    Your command should be

    Shell(Environ('comspec'), '/c move d:\nav\testfile1 \\10.7.7.86\nav')

    If you want to do it your way, use

    Shell(environ('comspec'), '/c cd /d d:\nav && copy testfile1 \\10.7.7.86\nav\*.* && del testfile1')

    If you want to accomplish something, first find the correct commands in the commandprompt, and after that's working, use NAV...


    Btw: I didn't check this. It should be working, but it might contain typo's or something like that...
  • manjusreemanjusree Member Posts: 79
    Hi,

    Thank you very much for the reply. I am trying to copy the file to a network barcode printer, so I am unable to use MOVE command. I tried SHELL command in the way you have mentioned. It works very well. But the confirmation dialogue box comes everytime and if I am going to take 500 barcode labels, I should press OK 500 times :(. I am not able to set my file path as text constant as I am suffixing my filename with an incrementing numeric.


    So I decided to go with WSH_Shell. What to say it works with MOVE command, but not with my CD-COPY-DEL series.my code is as follows:-


    Command := STRSUBSTNO('%1 cd /d D:\nav\ && copy textfile'+FORMAT(i)+'.PRN \\10.7.7.86\nav\*.* && del textfile'+FORMAT(i)+'.PRN',ENVIRON('COMSPEC'));
    WindowStyle := 0;
    WaitOnReturn := TRUE;
    IF ISCLEAR(WSH_Shell) THEN
    CREATE(WSH_Shell);
    ExitCode := WSH_Shell.Run(Command, WindowStyle, WaitOnReturn);

    Any help will be highly appreciated.

    Regards,
    Manjusree
  • PoltergeistPoltergeist Member Posts: 200
    Add a /c after %1. You need to tell the commandinterpreter to run a command, and that's done with /c.
  • manjusreemanjusree Member Posts: 79
    Hi,

    It works :)..thank you very very much. You saved my day :)

    Cheers,
    Manjusree
Sign In or Register to comment.