Focal Point
[SOLVED] Would like to understand how WINNT commands work

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7337038296

March 12, 2020, 02:05 AM
iDuncanW
[SOLVED] Would like to understand how WINNT commands work
Hi,

I have the following bit of code at the start of a program that creates a number of files in &MYPATH. The idea being that I want to delete all the files in that folder before I create all the new ones later in the program.

What I'm not sure is if the WINNT del command will complete before the rest of the program runs? If not, is there a way to make sure it does please?

 
-SET &MYPATH          = 'E:\mypath\';

-SET &DELETEFILE = &MYPATH | '*.*';
-RUN
-TYPE &DELETEFILE
-WINNT del /q /f &DELETEFILE
-RUN

The rest of my program here....

 


If there is a chance it won't have finished, I could end up with a mess of files in the folder.

Thanks,

Duncan

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8.2
Windows 10
XLSX, PDF
March 12, 2020, 04:03 AM
Tony A
Check out the SYSTEM function. This will populate a variable with the return code of the OS command so that you can test for success/failure before continuing.

Link to online help

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
March 12, 2020, 04:47 AM
iDuncanW
Hi Tony,

Thanks for the super quick reply. I had a look at the System command but I'm either doing something wrong or it doesn't work on our setup.

These were my two attempts:

   
-SET &RETURNCODE = SYSTEM(29, 'WINNT del /q /f E:\mypath\*.*', 'D4');
-TYPE returncode was &RETURNCODE


-SET &RETURNCODE = SYSTEM(31, 'COMMAND del /q /f E:\mypath\*.*', 'D4');
-TYPE returncode was &RETURNCODE


These are the results:
   
'WINNT' is not recognized as an internal or external command,
operable program or batch file.
returncode was -1


'COMMAND' is not recognized as an internal or external command,
operable program or batch file.
returncode was -1


It's nearly 8pm here so signing off until the morning now.

Cheers,

Duncan


WebFOCUS 8.2
Windows 10
XLSX, PDF
March 12, 2020, 07:50 AM
dbeagan
Try
-SET &RETURNCODE = SYSTEM(29, 'del /q /f E:\mypath\*.*', 'D4');
-TYPE returncode was &RETURNCODE



WebFOCUS 8.2.06
March 12, 2020, 04:54 PM
iDuncanW
Thanks dbeagan, that fixed it Cool

Handling the result?
If I understand the documentation correctly, I should just need to check that I got a value of 0 in &RETURNCODE as processing is suspended until the operation is complete?

Confirm understand of possible return values
Interestingly, even when the file was not found, the value of &RETURNCODE was still 0. Guessing for the SYSTEM command, I get '0' if I have submitted a valid command, regardless of whether if finds any files to delete and '-1' if there if it's an invalid command?


WebFOCUS 8.2
Windows 10
XLSX, PDF
March 13, 2020, 05:22 AM
Tony A
You will get a return code of 0 if the command is valid and the command ran successfully.

If you run your command (on the server remember!) using CMD.EXE then you will get the same response.

If you want to get differing return codes from your call then look at writing a python or powershell procedure to call that will give you more meaningful return codes.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
March 15, 2020, 05:22 PM
iDuncanW
Thanks Tony,

I think provided I get the 0 once the command has completed, I'm happy to let my program continue. If I get some time, I will explore the powershell option.


WebFOCUS 8.2
Windows 10
XLSX, PDF