Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29367 Discussions

System and SystemQQ: what am I doing wrong?

Barbuto__Fausto_Arin
1,524 Views

Hi,

I want to do something that is quite simple (I reckon).  I must go up one folder level, chdir to another folder and then delete one existing file in this latter folder.  What I'm doing is the following:

         Logical :: I

         I = SystemQQ('cd ..\Data\')
         I = SystemQQ('del CPG.dat')

However, it seems that not even the first command works, I mean, I cannot go up one level and then into the Data folder.  The command System (by the way, in what it differs from SystemQQ?) doesn't work either.  Same result if I split the first command:

         I = SystemQQ('cd ..')
         I = SystemQQ('cd Dados')
         I = SystemQQ('del CPG.dat')

What am I doing wrong?  My system's specs are appended below.

Thanks a lot for any help.

Fausto

Windows 7

Microsoft Visual Studio 2005
Version 8.0.50727.867  (vsvista.050727-8600)
Microsoft .NET Framework
Version 2.0.50727 SP2

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,524 Views

What you are doing wrong is expecting effects from a call to SYSTEM or SYSTEMQQ to persist across calls. They don't. Each call to these routines (or to the standard EXECUTE_COMMAND_LINE) spawns a new process to execute the command. For things that change the environment, such as 'cd', the effect is only for that spawned process and disappears when the call returns.

Instead you need to modify the running program's environment and you can do that using the CHANGEDIRQQ library routine. Or you can put the relative path in the file specification. I would also suggest that DELFILESQQ is a preferable way to delete files.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,525 Views

What you are doing wrong is expecting effects from a call to SYSTEM or SYSTEMQQ to persist across calls. They don't. Each call to these routines (or to the standard EXECUTE_COMMAND_LINE) spawns a new process to execute the command. For things that change the environment, such as 'cd', the effect is only for that spawned process and disappears when the call returns.

Instead you need to modify the running program's environment and you can do that using the CHANGEDIRQQ library routine. Or you can put the relative path in the file specification. I would also suggest that DELFILESQQ is a preferable way to delete files.

0 Kudos
Barbuto__Fausto_Arin
1,524 Views

Steve Lionel (Intel) wrote:

What you are doing wrong is expecting effects from a call to SYSTEM or SYSTEMQQ to persist across calls. They don't. Each call to these routines (or to the standard EXECUTE_COMMAND_LINE) spawns a new process to execute the command. For things that change the environment, such as 'cd', the effect is only for that spawned process and disappears when the call returns.

Instead you need to modify the running program's environment and you can do that using the CHANGEDIRQQ library routine. Or you can put the relative path in the file specification. I would also suggest that DELFILESQQ is a preferable way to delete files.

DELFILESQQ worked well.  No extra gyrations needed.  Thanks a lot.

Fausto

 

0 Kudos
Barbuto__Fausto_Arin
1,524 Views

Steve Lionel (Intel) wrote:

What you are doing wrong is expecting effects from a call to SYSTEM or SYSTEMQQ to persist across calls. They don't. Each call to these routines (or to the standard EXECUTE_COMMAND_LINE) spawns a new process to execute the command. For things that change the environment, such as 'cd', the effect is only for that spawned process and disappears when the call returns.

One thing that I forgot to mention was that the following command:

I = SystemQQ('del ..\Data\CPG.dat')

doesn't work either, and in this case things don't seem to be a matter of 'persistence' as everything I wanted to get done is condensed in one single command.  Whatever happened above?

Fausto

 

0 Kudos
Steven_L_Intel1
Employee
1,524 Views
C:\Projects\Lib1>type t.f90
use ifport
iret = SYSTEMQQ('del ..\Data\CPG.dat')
print *, iret
end
C:\Projects\Lib1>dir ..\Data\CPG.dat
 Volume in drive C is OSDisk
 Volume Serial Number is 6E33-836D

 Directory of C:\Projects\Data

06/30/2015  05:03 PM                 4 CPG.dat
               1 File(s)              4 bytes
               0 Dir(s)  712,683,151,360 bytes free

C:\Projects\Lib1>ifort t.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Inte
l(R) 64, Version 15.0.3.208 Build 20150407
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
-subsystem:console
t.obj

C:\Projects\Lib1>t.exe
           1

C:\Projects\Lib1>dir ..\Data\CPG.dat
 Volume in drive C is OSDisk
 Volume Serial Number is 6E33-836D

 Directory of C:\Projects\Data

File Not Found

C:\Projects\Lib1>

 

0 Kudos
Reply