One powerful tool here, is the ability to generate system shell calls, and here I'll talk about this on Windows machines, only.
QUEST BCL has a call named "SYSTEM" which takes a single string argument, enclosed in single quotes. The QUEST BCL documentation gives an example of copying a file:
SYSTEM 'copy thisfile thatfile'
where thisfile is the path to the file to copy, and thatfile is the path to the file you want to copy to. This is useful enough, and pretty self explanatory, especially if you've used the Windows command line enough.
The example I'd like to provide lays in launching applications, and in this case, Microsoft Excel. To simply launch a file from the command line, all you need to do is feed the command shell the path to the file to open. Windows knows how to handle pretty much any file type you throw at it, and in the traditional GUI use of Windows you're prompted if Windows doesn't know what to do with the file.
This works fine for files where there's only one program for viewing or editing a particular file type. But what happens if you want to chose what program to use? Using the command line shell, we can specify the program file to use to open a file by passing the path of our file as an argument in starting the application. Most major applications support this.
So if you have Open Office set as the default editor of Excel files, passing an Excel file to the command shell will open it in Open Office. But if for some reason you want to open this file in Excel (without changing the default behavior) we just have to start Excel with our file as a command line argument.
So here's an SCL routine you can use to launch an Excel file:
routine launch_excel( file_name : String ) : Integer
Const
EXCEL_LOCATION 'C:/Program Files (x86)/Microsoft Office/Office12/excel.exe'
Var
bclerr : Integer
bclmsg : String
Begin
bclmsg = "SYSTEM '" + EXCEL_LOCATION + " "
bclmsg = bclmsg + file_name
bclmsg = bclmsg + " &'"
if( EXCEL_LOCATION <> '' ) then
bclerr = bcl(bclmsg)
endif
return bclerr
End
All we're doing is using the SYSTEM BCL call with the file_name argument as a commmand line argument. Pretty simple, eh?
2 comments:
Hi Jon.
Could you please make some explanation about why using the operator "&" here?
Terence
I'm not entirely sure if it works properly, but appending the ampersand (&) symbol to the end of a command is supposed to mean the BCL command doesn't return to SCL until whatever system call you're calling finishes...
Post a Comment