Invoking Windows Shell Functions

In order to invoke a Windows shell function (such as a batch file or executable) from APPX for Windows, you can use a syntax similar to the following. (You'll have to break the SET statement apart into multiple APPENDs, but it is presented here as single strings, for clarity.)

Windows NT, APPX 4.0.2 and after:

SET --- TEMP 132 = cmd.exe /c C:\APPX\scripts\test.bat 
RUN --- TEMP 132

Windows 9x, APPX 4.0.2 and after:

SET --- TEMP 132 = C:\command.com /c C:\APPX\scripts\test.bat 
RUN --- TEMP 132

Windows NT, prior to APPX 4.0.2:

SET --- TEMP 132 = cmd.exe /c C:\\APPX\\scripts\\test.bat 
RUN --- TEMP 132

Windows 9x, prior to APPX 4.0.2:

SET --- TEMP 132 = C:\\command.com /c C:\\APPX\\scripts\\test.bat 
RUN --- TEMP 132

In the above example, "test.bat" contains some DOS copy commands. DOS commands (such as 'copy') don't work directly from APPX, because we are using a Windows "exec" function, which only knows how to start Windows programs. But running command.com from Windows, with the "/c" switch, creates a temporary DOS shell, which can then execute a DOS batch file.

The "/c" after cmd.exe and command.com specifies that the command interpreter is to perform the command specified by the string following it, in this case a batch file, and then stop.

Note that you can use option 6)Upper/Lower in the ILF editor to get lower case characters, such as 'cmd.exe'.

In releases 4.0.1 and prior, the double backslashes ("\\") are necessary to pass a single backslash ("\") thru to the windows shell, since backslash is used in DOS to denote special treatment of the following character.

In release 4.0.2 and after, the double backslash is no longer required.

Running command.com /c or cmd.exe /c is only necessary when invoking non-Windows native applications. This includes commands one would normally execute from the DOS popup box.

If you want to run a Windows-native application (such as notepad, or MS Access), you can invoke this directly without the command.com or cmd.exe /c prefix.

Without a preceding backslash, a "$" is an indicator of a substitution in the RUN command string based on a PASS statement. A backslash preceding a "$" tells APPX not to do a substitution but to allow the "$" to remain in the RUN command string.

(And the '%' symbol?)


In some applications, you might not want the DOS box to disappear after the external execution. For example a batch file that performed:

echo  -  display statement in the DOS box.

copy  -  execute statement and display in DOS box.

pause -  display "Press any key to continue" and 
         wait for user to press enter before 
         proceeding.

choice - display the message, waited for user to 
         make a valid selection 

To accomplish this, make a copy of COMMAND.COM and put it into a test directory. In the PROGRAM tab of PROPERTIES for this new file, deselect the "Close on Exit" check box. Then modify the APPX subroutine to invoke this test copy of COMMAND.COM. Now everything should continue to work fine and the box remain on screen. The title bar should at the end say: "Finished - " when complete.


The 4.0.2 change making double backslashes no longer required (ECR #3315) had a negative effect to the PowerQ application (ECR #4799).

After upgrading 3.4 to 4.0.2, a print job submitted to PowerQ and then released would continually print to the printer instead of stopping after the requested number of copies.

The reason was that the print queue daemon process was not getting back the results from the lp command as submitted by command "008 SUBMIT PRINT JOB". This command, as stored in the COMMANDS file, contained double backslashes. When these were changed to single backslashes the problem went away.


Under ECR #4799, the before and after for the command "008 SUBMIT PRINT JOB" are:

Before:

====================== ===== =======================================
013 REMOVE DIRECTO+------------------------------------------------+
014 SUBMIT JOB    &                       Command String           &
015 GET SESSION PI&                                                &
016 KILL TASK     &cat6                                            &
017 VIEW FILE     &{PRINTQ.HEX OPTIONS}6                           &
XX8 SUBMIT PRINT J&{BANNER FILE}6                                  &
                  &{PRINTQ.PATH FILE}6                             &
                  &|lp -oraw6                                      &
                  &{PRINTQ.SUBMIT DETAIL}6                         &
                  &2>&1 |awk '/^request id is/{print "0" \$4}6     &
                  &/^\\/usr\\/bin\\/lp/{print "1" \$0}'       &
                  &                                                &
                  &                                                &
                  +------------------------------------------------+

After:

000 GET HOST NAME +------------------------------------------------+
001 CANCEL PRINT J&                       Command String           &
002 GET PROCESS ID&                                                &
003 COPY A FILE   &cat6                                            &
004 REMOVE FILE   &{PRINTQ.HEX OPTIONS}6                           &
005 GET GROUP LIST&{BANNER FILE}6                                  &
005 START BACKGROU&{PRINTQ.PATH FILE}6                             &
006 LOOK FOR PRINT&|lp -oraw6                                      &
007 GET SYSTEM PRI&{PRINTQ.SUBMIT DETAIL}6                         &
008 SUBMIT PRINT J&2>&1 |awk '/^request id is/{print "0" \$4}6     &
009 GET DIRECTORY &/^\/usr\/bin\/lp/{print "1" \$0}'           &
010 GET NAME FROM &                                                &
011 GET SYSTEM JOB&                                                &
012 RENAME A FILE +------------------------------------------------+

Comments:

Read what other users have said about this page or add your own comments.



Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2012-02-29 - ChrisBrower
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback