Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29281 Discussions

System call and paths with blanks

aurora
Beginner
1,823 Views
Hello,

I have this problem when using system call:

The program i want to launch with system command, has blank spaces like

C:Program filesProgram Nameexcutable.exe

So i will have to use "". The thing is that if I try like this:

iflag=system(' "C:Program filesProgram Nameexcutable.exe" --in=C:inputfile ')

the case above works,

but when the inputfile is in a path with "spaces" and i try this:

iflag=system(' "C:Program filesProgram Nameexcutable.exe" --in="C:Documents and settingsinputfile" ')

If fails :(

It seems it doesn't like to have multiple (") in the same system call...but, how can i solve the issue with blank paths then?

Thank you in advance.

PS I have written the statements in a single line although in the real program it is splitted in several lines to avoid problems with the 72 maximum length
0 Kudos
5 Replies
anthonyrichards
New Contributor III
1,823 Views

In this case ShellExecute is your friend...


USE DFWINTY
TYPE (T_SHELLEXECUTEINFO) SHINFO
CHARACTER*100 EXCEL
INTEGER HWND
INTEGER IRET, retlog
! add your own path to your executable here, or use an environment variable
! that you define, and obtain it using GETENVQQ...
! EXCEL example
EXCEL="C:PROGRAM FILESMICROSOFT OFFICEOFFICEEXCEL.EXE"C
HWND=GETMODULEHANDLE(NULL)
SHINFO%cbSize=sizeof(SHINFO)
SHINFO%Fmask=SEE_MASK_NOCLOSEPROCESS
SHINFO%hwnd=HWND
SHINFO%lpVerb=loc('open'c)
SHINFO%lpFile=loc(EXCEL)
! ADD YOUR FILENAME HERE
SHINFO%lpParameters=loc("C:TEMPDUMMY.XLS"c )
SHINFO%lpDirectory=loc('C:'C)
SHINFO%nShow=SW_HIDE
retlog=ShellExecuteEx(SHINFO)
! CHECK FOR FAILURE...
if(SHINFO%hInstapp.lt.32) then
IRET=MESSAGEBOX(HWND,'Failed to find file//launch EXCEL'C, &
'Problem opening EXCEL'C, &
MB_ICONEXCLAMATION .OR. MB_OK)
endif
0 Kudos
Robinson__Donald
Beginner
1,823 Views
This issue still exists in 11.0.061 for both SYSTEM and SYSTEMQQ calls. In my case I want to pass 3 path-names, any of which may contain blanks. The pathnames are quoted to no avail. I suppose I will have to create a batch file, which seems like a lame solution that carries its own file management overhead. It seems to me like this is a deficiency that should be fixed.
0 Kudos
IanH
Honored Contributor III
1,823 Views
Have a read of the system help (as in Start button > Help and support) for cmd.exe and look at the remarks section. It has some guidelines for quoting. If I follow those things seem to work. In short - try one "super" pair of quotes around the entire line (with each file that contains spaces still in quotes):

[fortran]rc = systemqq('""comand with spaces" "arg with spaces one" "arg with spaces two""')[/fortran]
0 Kudos
GVautier
New Contributor III
1,823 Views
Hello


I think that your quotes in the argument are misplaced. You wrote

iflag=system(' "C:Program filesProgram Nameexcutable.exe" --in="C:Documents and settingsinputfile" ')

but I think that you must write

iflag=system(' "C:Program filesProgram Nameexcutable.exe" "--in=C:Documents and settingsinputfile" ')

because quotes are removed in arguments by the system launcher so the first argument of your executable will be correct.
0 Kudos
Robinson__Donald
Beginner
1,823 Views
Thanks Ian - I hadn't seen that bit of help. I'll try this.
0 Kudos
Reply