@@ -774,31 +774,32 @@ subroutine filewrite(filename,filedata)
774
774
775
775
end subroutine filewrite
776
776
777
- function which (command ) result(pathname)
777
+ ! >AUTHOR: John S. Urban
778
+ ! !LICENSE: Public Domain
778
779
! >
779
- ! !##NAME
780
+ ! !##Name
780
781
! ! which(3f) - [M_io:ENVIRONMENT] given a command name find the pathname by searching
781
782
! ! the directories in the environment variable $PATH
782
783
! ! (LICENSE:PD)
783
784
! !
784
- ! !##SYNTAX
785
+ ! !##Syntax
785
786
! ! function which(command) result(pathname)
786
787
! !
787
788
! ! character(len=*),intent(in) :: command
788
789
! ! character(len=:),allocatable :: pathname
789
790
! !
790
- ! !##DESCRIPTION
791
+ ! !##Description
791
792
! ! Given a command name find the first file with that name in the directories
792
793
! ! specified by the environment variable $PATH.
793
794
! !
794
- ! !##OPTIONS
795
+ ! !##options
795
796
! ! COMMAND the command to search for
796
797
! !
797
- ! !##RETURNS
798
+ ! !##Returns
798
799
! ! PATHNAME the first pathname found in the current user path. Returns blank
799
800
! ! if the command is not found.
800
801
! !
801
- ! !##EXAMPLE
802
+ ! !##Example
802
803
! !
803
804
! ! Sample program:
804
805
! !
@@ -812,11 +813,7 @@ function which(command) result(pathname)
812
813
! ! write(*,*)'install is ',which('install')
813
814
! ! end program demo_which
814
815
! !
815
- ! !##AUTHOR
816
- ! ! John S. Urban
817
- ! !##LICENSE
818
- ! ! Public Domain
819
-
816
+ function which (command ) result(pathname)
820
817
character (len=* ),intent (in ) :: command
821
818
character (len= :),allocatable :: pathname, checkon, paths(:), exts(:)
822
819
integer :: i, j
@@ -854,8 +851,66 @@ function which(command) result(pathname)
854
851
enddo SEARCH
855
852
end function which
856
853
857
- ! > echo command string and pass it to the system for execution
858
- ! call run(cmd,echo=.false.,exitstat=exitstat,verbose=.false.,redirect='')
854
+ ! >AUTHOR: fpm(1) contributors
855
+ ! !LICENSE: MIT
856
+ ! >
857
+ ! !##Name
858
+ ! ! run(3f) - execute specified system command and selectively echo
859
+ ! ! command and output to a file and/or stdout.
860
+ ! ! (LICENSE:MIT)
861
+ ! !
862
+ ! !##Syntax
863
+ ! ! subroutine run(cmd,echo,exitstat,verbose,redirect)
864
+ ! !
865
+ ! ! character(len=*), intent(in) :: cmd
866
+ ! ! logical,intent(in),optional :: echo
867
+ ! ! integer, intent(out),optional :: exitstat
868
+ ! ! logical, intent(in), optional :: verbose
869
+ ! ! character(*), intent(in), optional :: redirect
870
+ ! !
871
+ ! !##Description
872
+ ! ! Execute the specified system command. Optionally
873
+ ! !
874
+ ! ! + echo the command before execution
875
+ ! ! + return the system exit status of the command.
876
+ ! ! + redirect the output of the command to a file.
877
+ ! ! + echo command output to stdout
878
+ ! !
879
+ ! ! Calling run(3f) is preferred to direct calls to
880
+ ! ! execute_command_line(3f) in the fpm(1) source to provide a standard
881
+ ! ! interface where output modes can be specified.
882
+ ! !
883
+ ! !##Options
884
+ ! ! CMD System command to execute
885
+ ! ! ECHO Whether to echo the command being executed or not
886
+ ! ! Defaults to .TRUE. .
887
+ ! ! VERBOSE Whether to redirect the command output to a null device or not
888
+ ! ! Defaults to .TRUE. .
889
+ ! ! REDIRECT Filename to redirect stdout and stderr of the command into.
890
+ ! ! If generated it is closed before run(3f) returns.
891
+ ! ! EXITSTAT The system exit status of the command when supported by
892
+ ! ! the system. If not present and a non-zero status is
893
+ ! ! generated program termination occurs.
894
+ ! !
895
+ ! !##Example
896
+ ! !
897
+ ! ! Sample program:
898
+ ! !
899
+ ! ! Checking the error message and counting lines:
900
+ ! !
901
+ ! ! program demo_run
902
+ ! ! use fpm_filesystem, only : run
903
+ ! ! implicit none
904
+ ! ! logical,parameter :: T=.true., F=.false.
905
+ ! ! integer :: exitstat
906
+ ! ! character(len=:),allocatable :: cmd
907
+ ! ! cmd='ls -ltrasd *.md'
908
+ ! ! call run(cmd)
909
+ ! ! call run(cmd,exitstat=exitstat)
910
+ ! ! call run(cmd,echo=F)
911
+ ! ! call run(cmd,verbose=F)
912
+ ! ! end program demo_run
913
+ ! !
859
914
subroutine run (cmd ,echo ,exitstat ,verbose ,redirect )
860
915
character (len=* ), intent (in ) :: cmd
861
916
logical ,intent (in ),optional :: echo
0 commit comments