db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Nielsen <Thomas.Niel...@Sun.COM>
Subject Re: running ij commands from a code in c
Date Thu, 14 Jun 2007 10:39:34 GMT
So...

The idea is to do something similar to a java System.exec(), which you 
probably already know, but c-style.

The approach depends on which OS you're running.

Use something like system() on unix/linux, or CreateProcess() on 
windows. These calls take a commandline in and gives you an exitvalue in 
return.

system(2) executes the supplied commandline in a new shell by doing a 
fork, exec and wait under the covers, while the CreateProcess() call 
basically does the same thing internally windows-style. This is 
identical to typing it on the commandline and hitting return.

Unix/Linux:
    ...
    int retval = system("path/to/ij whateverscript.ij");
    ...

Windows:
    ...
    int retval = CreateProcess("path/top/ij whateverscript.ij", ...);
    ...

Wrap in OS specific main() function with necessary includes and you have 
your basic forkworld-example :)

You can also do fork, exec and wait yourself if you want more control. 
There are variations available as well if you want even greater 
flexibility or control - depending on OS.

OS programmers guides usually have a dedicated chapter or section on how 
to do this. Manpages contain the a lot of information for unix/linux, 
and MSDN gives you the details in case of Windows.

Needless to say as people do write books about this, there are some 
caveats and gotchas. But we'll leave those to the authors.

Hopefully enough to get you going :)

HTH,
Thomas


Tony Winslow wrote:
> I'm interested in that:
> "fork a new process running ij".
> I virtually know nothing about that topic.
> Could you please give me some simple
> "HelloWorld" example on that?
> 
> 2007/6/14, Thomas Nielsen <Thomas.Nielsen@sun.com 
> <mailto:Thomas.Nielsen@sun.com>>:
> 
>     yarono,
> 
>     If Tonys suggestion of looking at org.apache.derby.impl.tools.ij doesn't
>     give you what you need, then your last resort would probably be to fork
>     a new process running ij with a command script (that does what you
>     do at
>     the ij prompt today) to do your db creation / shutdown. Check the
>     exitvalue and/or parse the output from the process to deduce success or
>     failure the create/shutdown steps.
> 
>     Cheers,
>     Thomas
> 
>     yarono wrote:
>      > What I'm trying to do is to create DB's and shut them down - all
>     from my code
>      > in c.
>      >
>      > My current status is that I'm able to perform the above functions
>     (meaning
>      > create DB and shutdown) via the ij prompt, run my code to perform
>     table
>      > creation, insertions, etc.. The shutdown and creation of the db's
>     is done
>      > through the ij prompt, while the rest of my code is in c.
>      >
>      > I want the whole thing to be done in c.
>      >
>      >
>      > Thomas Nielsen - Sun Microsystems - Trondheim, Norway wrote:
>      >> hi yarono,
>      >>
>      >> What exactly do you want to do?
>      >> - fork a new process to run ij (with or without a SQL script)?
>      >> - execute SQL commands from C?
>      >>
>      >> If you are trying to fork a new process running ij, then please
>     refer to
>      >> a suitable OS programmers guide on how to do this.
>      >>
>      >> If you are trying to execute SQL in C, then you're looking for a
>     ODBC
>      >> driver. Derby does not come with a (free) ODBC driver, so your
>     options
>      >> are to buy a (DRDA capable) ODBC driver, or use a ODBC-JDBC bridge
>      >> driver with the Derby JDBC driver. Not aware of any free ODBC-JDBC
>      >> bridge drivers off the top of my head if free is what you are
>     looking for.
>      >>
>      >> Hope this helps :)
>      >>
>      >> Cheers,
>      >> Thomas
>      >>
>      >> yarono wrote:
>      >>> Is there a way to run the 'ij commands' in my code (written in
>     c), just
>      >>> as I
>      >>> execute SQL statements?
>      >> --
>      >> Thomas Nielsen
>      >>
>      >>
>      >
> 
>     --
>     Thomas Nielsen
> 
> 

-- 
Thomas Nielsen

Mime
View raw message