Re: Problem in calling c programs and compiling them in tcl/tk
- From: Uwe Klein <uwe_klein_habertwedt@xxxxxxxxxxx>
- Date: Tue, 11 Nov 2008 14:38:58 +0100
vasavi.naga@xxxxxxxxx wrote:
On Nov 11, 5:35 pm, "Larry W. Virden" <lvir...@xxxxxxxxx> wrote:
On Nov 11, 5:23 am, vasavi.n...@xxxxxxxxx wrote:
Hello,
I have been assigned to open a directory with c
programs in it using tcl/tk. Later I am supposed to c ompile all those
c programs in that directory one after another using tclk/tk.
I am able to open the directory and read all the c files.
Are you using Tcl's glob command to do this? If not, read up on it -http://wiki.tcl.tk/glob- for a nice way to get back the names of
files in a directory.
But when it
comes to compiling them am not able to do it at all. I have tried
using exec gcc filename.c and later exec ./a.out filename.c. For
This is pretty close to the right thing, though I would recommend
something more along the lines of
exec gcc filename.c -o filename
(or whatever other name seems appropriate - some people use
filename.exe).
Otherwise, the first compiled program isn't after you have compiled
the next file.
example , if i take helloworld.c program & write above 2 steps , its
showing the o/p as "helloworld" . But it's also saying like child
process exited abnormally.
There are two possibilities here.
1. Your program doesn't have an explicit return code, or the return
code is non-zero.
For example:
$ $ cat helloworld.c
#include <stdio.h>
void main()
{
printf("hello, world\n");}
$ gcc ./helloworld.c
helloworld.c: In function `main':
helloworld.c:4: warning: return type of `main' is not `int'
srv29 (35795) $ ./a.out
hello, world
srv29 (35796) $ echo $?
1
$ tclsh8.5
% ./a.out
hello, world
child process exited abnormally
2. Your program is writing to stderr instead of stdout.
In this case, if you are using Tcl 8.5, you can look at the exec's -
ignorestderr flag.
In both of these cases, you should also read about Tcl's catch command
athttp://wiki.tcl.tk/catch.
This is a basic technique that allows you to gather information about
the execution of a command that might generate a Tcl error.
Unfortunately, there's not a general way of looking at the results and
saying "any time I see this, I can ignore it". Each command that needs
"caught" should be thought of as unique and the results checked.
If the command is documented as returning special return codes or
special output, then you could always check for that.
All the fork and thread concepts are quite new
and confusing to me. Isn't there any simple command in tcl from which
i can call a c program and compile it ?
You are using the right thing - you just missed some of the
documentation. Be sure to read the documentation for exec -http://wiki.tcl.tk/exec- for information about catch, checking for
error codes, etc.
hello,
I am not getting it. I tried to use like
1) exec /path../filename.c 2>@ stderr
then I got o/p like -- syntax error at printf ("hello world");
child process exited abnormally
Hehe, the system tries to execute a .c file as a shellscript.
( which should not work in any case as it should not be executable )
# find all files *.c
set files_c [ glob -types f "./*.c" ]
foreach file $files_c {
set aout [ string range $file 0 end-2 ]
# compile code to executable:
catch {exec gcc -o $aout $file } cerr
puts stderr "compiling $file to $aout : $cerr"
# run created executable
catch {exec ./$output} cerr
puts stderr "running executable $aout : $cerr"
}
# this is rather primitive, it does not act on compile failure.
# is this assigned work from school?
uwe
.
- Follow-Ups:
- Re: Problem in calling c programs and compiling them in tcl/tk
- From: Larry W. Virden
- Re: Problem in calling c programs and compiling them in tcl/tk
- References:
- Problem in calling c programs and compiling them in tcl/tk
- From: vasavi . naga
- Re: Problem in calling c programs and compiling them in tcl/tk
- From: Larry W. Virden
- Re: Problem in calling c programs and compiling them in tcl/tk
- From: vasavi . naga
- Problem in calling c programs and compiling them in tcl/tk
- Prev by Date: Re: Problem in calling c programs and compiling them in tcl/tk
- Next by Date: Re: Problem in calling c programs and compiling them in tcl/tk
- Previous by thread: Re: Problem in calling c programs and compiling them in tcl/tk
- Next by thread: Re: Problem in calling c programs and compiling them in tcl/tk
- Index(es):
Relevant Pages
|