- To run external commands while editing a file in vim, use the '!' in the normal mode. For example
:!ls -al
will list the files:!date
will display the current date. - To read the output of external commands into the current file, do
:r !date
All the commands are run in normal mode. Press ESC key to enter the normal mode in vim.
Further reading:- :help :! - To run external commands in octave, use the system command. Sample octave session looks as
$octave -q
Further reading :- "doc system" shows the relevant help pages in octave.
octave:1> system("date")
Thu Jun 4 23:49:23 EDT 2009
ans = 0
octave:2> [ret_code output] = system("date");
octave:3> ret_code
ret_code = 0
octave:4> output
output = Thu Jun 4 23:49:40 EDT 2009
octave:5> exit - To run external commands in Fortran 90 programs, use the system command. Sample code looks as below
$cat system.f90
program callsystem
implicit none
!to examine the behaviour of the system command
character (len=100)::cmd
cmd="echo Wake up Neo"
!if u are using ifc compiler use -Vaxlib during compilation
call system(cmd//achar(0))
call system(cmd)
call system("date")
! The next line also works.
! call system("ls")
end program callsystem
$gfortran system.f90
$./a.out
Wake up Neo
Wake up Neo
Thu Jun 4 23:55:07 EDT 2009 - To run the external commands in C, use the system command available in stdlib.h. Sample code will be
$cat system.c
#include stdio.h
#include stdlib.h
int main() {
/* Fixme :- <, > in the header files are not showing up on blogspot */
int ret_code;
ret_code = system("date");
printf("%d\n", ret_code);
return 0;
}
$gcc -Wall system.c
$./a.out
Fri Jun 5 00:04:14 EDT 2009
0
Further reading :- man system
All the above are tested in Debian Lenny using vim 7.1, octave 3.0.1, gfortran 4.3.1, gcc 4.3.1
Malayamarutham is a mellifluous raaga in carnatic music which will make one soft at heart. In telugu, malaya maarutham is a cool evening breeze which invigorates mind, body & heart.
Feedback, suggestions, criticisms, typos, mistakes, errors etc., (no matter how small you think they are) on the articles of this blog are very welcome. They can be directed to kamaraju at gmail dot com.
Search This Blog
Thursday, June 04, 2009
running external commands
Labels:
c tips,
external_commands,
fortran tips,
octave tips,
vim tips
Subscribe to:
Post Comments (Atom)
2 comments:
You have a great blog here, lots of useful information presented in an easy to read format. Well done - your feed has a home in my reader from now on.
Thanks for the kind words. That just made my day!
Post a Comment