call system('cd sub_dir') 
Author Message
 call system('cd sub_dir')

Hello,

    I have these lines in a fortran program

    call system('pwd')
    call system('cd A_SUB_DIR')
    call system('pwd')

which compiles and executes but the call to system to change
the directory works but does not change the directory. (I know it is
executed
because if I ask to cd to a  non existing subdir crashes the program)

    Does the second call fork a sub shell process and the program
continues to
run in the current directory?

    Could anyone please clarify this?! So I cannot change directory from
a fortran
program?!

    Many thanks,
    Zuheyr

--
Dr. Zuheyr Alsalihi
von Karman Institute



Sun, 10 Oct 2004 20:39:31 GMT  
 call system('cd sub_dir')
Hi,



Quote:
> Hello,

>     I have these lines in a fortran program

>     call system('pwd')
>     call system('cd A_SUB_DIR')
>     call system('pwd')

> which compiles and executes but the call to system to change
> the directory works but does not change the directory. (I know it is
> executed
> because if I ask to cd to a  non existing subdir crashes the program)

>     Does the second call fork a sub shell process and the program
> continues to
> run in the current directory?

Depends on your implementation ( system is not part of standard
Fortran ), but given this is the way Unix likes to operate I
would strongly suspect this is the case

Quote:

>     Could anyone please clarify this?! So I cannot change directory from
> a fortran
> program?!

Well given that Fortran has no concept of directories it's pretty
difficult !

There may be a way, but it will depend on the compiler you are
using. You will have to dig out the documentation and have a look,

Ian



Sun, 10 Oct 2004 21:07:24 GMT  
 call system('cd sub_dir')

Quote:

>Hello,

>    I have these lines in a fortran program

>    call system('pwd')
>    call system('cd A_SUB_DIR')
>    call system('pwd')

>which compiles and executes but the call to system to change
>the directory works but does not change the directory. (I know it is
>executed
>because if I ask to cd to a  non existing subdir crashes the program)

>    Does the second call fork a sub shell process and the program
>continues to
>run in the current directory?

On all systems that I know of that accept the system extension,
call system forks a subshell that executes the given command.
For instance, call system ("pwd ; cd sub_dir ; pwd") will provide
the desired output, but probably it still is not what you want.

Quote:

>    Could anyone please clarify this?! So I cannot change directory from
>a fortran
>program?!

Fortran has no concept of a directory. What do you expect a change
of directory from a fortran program to do ? On some systems, some
of the effects that you might want to achieve might be done with
a 'call setenv ("PWD","newdir")' or similar instruction.

Michel

--

 http://www.ifremer.fr/metocean/group/michel/michel_olagnon.htm
 http://www.fortran-2000.com/



Sun, 10 Oct 2004 21:27:03 GMT  
 call system('cd sub_dir')

Quote:

> >     Could anyone please clarify this?! So I cannot change directory from
> > a fortran
> > program?!

> Well given that Fortran has no concept of directories it's pretty
> difficult !

> There may be a way, but it will depend on the compiler you are
> using. You will have to dig out the documentation and have a look,

> Ian

As you seem to be working on a UNIX system, use the chdir() system
function. If you are lucky, there will be a Fortran-callable version,
otherwise you will need to interface to the C routine.

(Actually, this would be a problem in C as well: it does not have
any idea about directories either, apart from the routines supplied
by the system).

Regards,

Arjen



Sun, 10 Oct 2004 21:30:43 GMT  
 call system('cd sub_dir')
Zuheyr:  Put the system commands that you want to issue  into a Batch file
and use the SYSTEM command to run that .BAT file or system script. You can
test that .BAT or script file independently before you run it from Fortran SYSTEM.

Skip Knoble, Penn State

-|Hello,
-|
-|    I have these lines in a fortran program
-|
-|    call system('pwd')
-|    call system('cd A_SUB_DIR')
-|    call system('pwd')
-|
-|which compiles and executes but the call to system to change
-|the directory works but does not change the directory. (I know it is
-|executed
-|because if I ask to cd to a  non existing subdir crashes the program)
-|
-|    Does the second call fork a sub shell process and the program
-|continues to
-|run in the current directory?
-|
-|    Could anyone please clarify this?! So I cannot change directory from
-|a fortran
-|program?!
-|
-|    Many thanks,
-|    Zuheyr

   Herman D. (Skip) Knoble, Research Associate

   Web: http://www.personal.psu.edu/hdk
   Academic Services and Emerging Technologies
   Penn State University
     214C Computer Building
     University Park, PA 16802-2101
   Phone:+1 814 865-0818   Fax:+1 814 863-7049



Sun, 10 Oct 2004 21:37:18 GMT  
 call system('cd sub_dir')


Quote:
>     Does the second call fork a sub shell process and the program
> continues to
> run in the current directory?

Yes, on unix machines, this is what happens.  The "pwd" commend gets
executed in a different subprocess than the "cd" command.  

If you are on a unix-like machine that supports the POSIX fortran
interface, then there is a posix command to change the working
directory.  I don't have a reference handy, but it is probably
"pxf_chdir()" or something similar.  If your machine doesn't support the
POSIX interface, then there may be a nonstandard replacement.

$.02 -Ron Shepard



Sun, 10 Oct 2004 23:12:51 GMT  
 call system('cd sub_dir')

Quote:

> Hello,

>     I have these lines in a fortran program

>     call system('pwd')
>     call system('cd A_SUB_DIR')
>     call system('pwd')

> which compiles and executes but the call to system to change
> the directory works but does not change the directory. (I know it is
> executed
> because if I ask to cd to a  non existing subdir crashes the program)

>     Does the second call fork a sub shell process and the program
> continues to
> run in the current directory?

Will depend on implementation, but in your case, apparently...

Since knowledge of the underlying OS file structure is not within the
scope of Fortran, you'll have to look at whether your system provides a
mechanism to change the working directory of the process you're
executing from within the process..

If the problem is to find a file for input, you may have to resort to
either naming the file explicitly or using a batch or command file to
move to the desired subdirectory prior to invoking the program.



Sun, 10 Oct 2004 23:33:55 GMT  
 call system('cd sub_dir')

Quote:

> ...
> If you are on a unix-like machine that supports the POSIX fortran
> interface, then there is a posix command to change the working
> directory.  I don't have a reference handy, but it is probably
> "pxf_chdir()" or something similar.

Yes.  The POSIX-compliant call is simply:

        call pxfchdir (path, ilen, ierror)
where:
        path - character string with desired path name
        ilen - # of significant characters in 'path' (use 0 to
                simply ignore trailing blanks)
        ierror - returns errno (0 if all ok)

Quote:
>  If your machine doesn't support the
> POSIX interface, then there may be a nonstandard replacement.

Walt
-...-
Walt Spector
(w6ws at earthlink dot net)


Wed, 13 Oct 2004 22:11:08 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. a Perl script's interaction with Ruby's system call

2. g77, cygwin, CALL System('cls')

3. SPARCompiler F90 1.1 intrinsic 'system' call

4. Plugin 2.0, socket, 'interrupted system call'

5. want code/info for playing audio cd's in CD-ROM

6. Fujitsu Software's COBOL CD's

7. WSA'93: Call for System Demonstrations

8. PDK'91 -- PRELIMINARY PROGRAM and CALL FOR SYSTEM DEMONSTRATIONS

9. WSA'93: Call for System Demonstrations

10. puts sometimes gives:in `write': Interrupted system call (Errno::EINTR)

11. WSA'93: Call for System Demonstrations

12. SRFI's for POSIX System Calls, and B-Trees

 

 
Powered by phpBB® Forum Software