Re: Problem in calling c programs and compiling them in tcl/tk



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
.



Relevant Pages

  • Re: Minimal Forth
    ... Compile the whole command before execution, rather than interpretating it word by word, because it's word by word execution that makes commands behave differently from saved defintions in traditional Forths. ... How would you cope with the kind of defining words that set up variables, constants, etc. that currently need to be used in execution mode? ...
    (comp.lang.forth)
  • Re: Problem in calling c programs and compiling them in tcl/tk
    ... using exec gcc filename.c and later exec ./a.out filename.c. ... the execution of a command that might generate a Tcl error. ... Be sure to read the documentation for exec -http://wiki.tcl.tk/exec-for information about catch, ...
    (comp.lang.tcl)
  • Re: Ordering large files (in perl?)
    ... use the sort ... >> execution to your program, ... > On looking further into this, I guess it isn't only that exec() only ... >> the command line and see if it does what you want, ...
    (comp.lang.perl.misc)
  • Re: ORA-06512 when I put JOB_DBMS.INTERVAL
    ... I put this command and it works. ... I confused with single quote and ... exec DBMS_JOB.INTERVAL') ... how can we check the next execution of a job ...
    (comp.databases.oracle.server)
  • Re: wScript.Shell Problems
    ... the completion of the underlying process. ... However, the Exec procedure is ... Here is why i went to the RUN command, it is my understanding that the ... EXEC command does not allow for the BOOLEAN indicating wether the ...
    (microsoft.public.scripting.vbscript)