DOS Access from Navision

chiramel
Member Posts: 23
Is it Possible to run one command in DOS from navision?
regards
febin
regards
febin
Febin Chiramel
Mumbai
India
Mumbai
India
0
Comments
-
See the SHELL command in the C/AL manual0
-
how to pass one caommand into dos by using shell
any body can give some examples or related linksFebin Chiramel
Mumbai
India0 -
[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!0 -
use shell() or WSH.
Which command do you will send to DOS :?:Do you make it right, it works too!0 -
I want to simply run Command prompt and pass DIR command.
ThanksFebin Chiramel
Mumbai
India0 -
Something like SHELL(ENVIRON('comspec'), ' /c dir *.* > file.txt')0
-
Its not working yaarFebin Chiramel
Mumbai
India0 -
What's not working? do you see any messages. Replace /c with /k to see what happens...0
-
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
India0 -
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? :?:Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
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 /?0 -
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 Tool0 -
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!0 -
Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
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)0 -
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...0 -
Why not use the virtual file table in nav? :-k
Regards
Thomas0 -
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,
Manjusree0 -
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...0 -
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\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,
Manjusree0 -
Add a /c after %1. You need to tell the commandinterpreter to run a command, and that's done with /c.0
-
Hi,
It works..thank you very very much. You saved my day
Cheers,
Manjusree0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions