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? :?:
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 /?
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
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!
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.
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...
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);
Comments
any body can give some examples or related links
Mumbai
India
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Which command do you will send to DOS :?:
Thanks
Mumbai
India
Mumbai
India
But its default path i'm seeing is licence file path......
where this path is storing ....
Do you have any Idea...
Mumbai
India
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
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 /?
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:
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
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)
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...
Regards
Thomas
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
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...
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,
Manjusree
It works ..thank you very very much. You saved my day
Cheers,
Manjusree