Using Backslashes with the SYSTEM and SPAWN Functions

Last reviewed: December 11, 1995
Article ID: Q59603
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, and 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, and 5.1
  • Microsoft FORTRAN PowerStation for MS-DOS, versions 1.0 and 1.0a
  • Microsoft FORTRAN PowerStation 32 for Windows NT, version 1.0 and 4.0

SUMMARY

Care should be taken when using backslash (\) characters in strings passed to the SYSTEM and SPAWN functions. The SYSTEM and SPAWN functions are actually C routines. In C, the backslash character is used to denote an editing descriptor, somewhat similar to the way the I, F, X, etc., editing descriptors are used in the FORTRAN FORMAT statement. The following sample SYSTEM call incorrectly uses the backslash character:

   I = SYSTEM('dir c:\temp'C)

No compile warnings are given, but a run-time error is produced because \t is interpreted as an editing descriptor.

NOTE: Under Fortran PowerStation 4.0, a compiler warning is generated for the line above. The warning message is:

   warning FOR4552: unrecognized character escape sequences in C-string

The C function associated with the FORTRAN SYSTEM function will interpret the backslashes as editing descriptors. In C, if you want to print out a backslash you must follow the first backslash with another; this tells C to temporarily ignore the backslash as an editing descriptor. The following line demonstrates how to properly use the backslash character in the SYSTEM and SPAWN functions:

   I = SYSTEM('dir c:\\temp'C)

NOTE: In FORTRAN PowerStation, SYSTEMQQ is equivalent to SYSTEM.


Additional reference words: kbinf 1.00 4.00 4.10 5.00 5.10
KBCategory: kbprg
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 11, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.