By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

C wrapper for Java program?

P: n/a
I'm trying to write a C wrapper to run a Java program. I need to
distribute a CD with the Java runtime, my application and a C startup
program. I've put the C wrapper program, my java app and the runtime
directories in the same directory. It will run under MS XP or maybe
Vista. I'm using MS Visual C++ Express 2005 for a compiler and I tried
using the _execl and _spawnl functions. These all give me assertion
errors and file not found errors. There is some issue with the path.
Do _execl() and _spawnl() need absolute paths to the files? Any ideas
or directions would be greatly appreciated.

Thanks,

--

Knute Johnson
email s/nospam/knute/
Nov 1 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Knute Johnson wrote:
I'm trying to write a C wrapper to run a Java program. [..]
You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 1 '07 #2

P: n/a
Victor Bazarov wrote:
Knute Johnson wrote:
>I'm trying to write a C wrapper to run a Java program. [..]

You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V
Victor are you the local PITA? There is one in every newsgroup. Did
you not see I was using a C++ compiler to write the program. As far as
I know C is still a subset of C++. Go pound sand if you don't want to
be helpful.

Every program has to run on some OS and if asking how to write a wrapper
program with a C++ compiler isn't a C++ question then I will quietly
go away. Describing my environment was only to provide information that
might be necessary to my problem. I will happily accept a 'pure' C++
solution. Any assistance is greatly appreciated.

Thankyou,

--

Knute Johnson
email s/nospam/knute/
Nov 1 '07 #3

P: n/a
Knute Johnson wrote:
Victor Bazarov wrote:
>Knute Johnson wrote:
>>I'm trying to write a C wrapper to run a Java program. [..]

You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V

Victor are you the local PITA?
Nope. He is a regular who has helped many people in the past.
There is one in every newsgroup. Did you not see I was using a C++
compiler to write the program.
What compiler you use is irrelevant for whether your question is topical.
As far as I know C is still a subset of C++.
Nit: It is not. There are many legal C programs that are illegal in C++ and
many legal C programs that happen to be legal C++, too, but have different
behavior when interpreted as C++ programs. There is, however, a non-empty
intersection of C and C++.
Go pound sand if you don't want to be helpful.

Every program has to run on some OS and if asking how to write a wrapper
program with a C++ compiler isn't a C++ question then I will quietly
go away. Describing my environment was only to provide information that
might be necessary to my problem. I will happily accept a 'pure' C++
solution. Any assistance is greatly appreciated.
Your specific question was:
I'm using MS Visual C++ Express 2005 for a compiler and I tried
using the _execl and _spawnl functions. These all give me assertion
errors and file not found errors. There is some issue with the path.
Do _execl() and _spawnl() need absolute paths to the files?
A search in my pdf-file of the C++ standard did not find _execl() nor
_spawnl(), and I also did not find it incorporated by reference from the C
standard. This pretty much is is the extend to which your question can be
answered topically in this forum. So in the end, Victor might be right and
you might be better off someplace where _execl() and _spawnl() are known.

On the other hand, you could just give absolute path names a try and see
whether that cures your problem.

Best

Kai-Uwe Bux

Nov 1 '07 #4

P: n/a
LR
Knute Johnson wrote:
Victor Bazarov wrote:
>Knute Johnson wrote:
>>I'm trying to write a C wrapper to run a Java program. [..]

You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V

Victor are you the local PITA? There is one in every newsgroup. Did
you not see I was using a C++ compiler to write the program.
I don't think this is a true statement. If you want to write a C
language wrapper or any other kind of C language program, you are going
to use a C compiler. VS 2005 Express is an IDE. Not a compiler.
As far as
I know C is still a subset of C++.
I don't believe that is formally true, and depending on what version of
C you are speaking of, it may be less true now than it was.
Go pound sand if you don't want to
be helpful.


Every program has to run on some OS
I know from personal experience that this is not true. I've written
code that ran on machines with no OS.
and if asking how to write a wrapper program
In C.
with a C++ compiler
Doubtful.


isn't a C++ question then I will quietly go away.
I don't think there's any need to be quiet about it. But I honestly
don't think that you've asked a question about the C++ language. That's
what is on topic in this group. Yes, there are occasional exceptions.

Questions that are about specific compilers, even C++ compilers, are not
generally on topic here.
Describing my environment was only to provide information that
might be necessary to my problem.
I think that you will probably find more help in a group devoted to your
compiler.
I will happily accept a 'pure' C++ solution.
For reasons that I think are as yet unknown, at least to me,
www.parashift.com is down, but according to a recent post you can see
here, http://groups.google.com/group/comp....d88a0d48be6eec
the most recent copy of the FAQ is here
http://www.cs.technion.ac.il/users/y.../FAQs/c++-faq/

You can read more about where to get help with your particular problem
here
http://www.cs.technion.ac.il/users/y...t.html#faq-5.9
Any assistance is greatly appreciated.
HTH

LR
Nov 1 '07 #5

P: n/a
Kai-Uwe Bux wrote:
Knute Johnson wrote:
>Victor Bazarov wrote:
>>Knute Johnson wrote:
I'm trying to write a C wrapper to run a Java program. [..]
You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V
Victor are you the local PITA?

Nope. He is a regular who has helped many people in the past.
>There is one in every newsgroup. Did you not see I was using a C++
compiler to write the program.

What compiler you use is irrelevant for whether your question is topical.
>As far as I know C is still a subset of C++.

Nit: It is not. There are many legal C programs that are illegal in C++ and
many legal C programs that happen to be legal C++, too, but have different
behavior when interpreted as C++ programs. There is, however, a non-empty
intersection of C and C++.
>Go pound sand if you don't want to be helpful.

Every program has to run on some OS and if asking how to write a wrapper
program with a C++ compiler isn't a C++ question then I will quietly
go away. Describing my environment was only to provide information that
might be necessary to my problem. I will happily accept a 'pure' C++
solution. Any assistance is greatly appreciated.

Your specific question was:
>I'm using MS Visual C++ Express 2005 for a compiler and I tried
using the _execl and _spawnl functions. These all give me assertion
errors and file not found errors. There is some issue with the path.
Do _execl() and _spawnl() need absolute paths to the files?

A search in my pdf-file of the C++ standard did not find _execl() nor
_spawnl(), and I also did not find it incorporated by reference from the C
standard. This pretty much is is the extend to which your question can be
answered topically in this forum. So in the end, Victor might be right and
you might be better off someplace where _execl() and _spawnl() are known.

On the other hand, you could just give absolute path names a try and see
whether that cures your problem.
OK, I'm sorry I even mentioned C. I won't do it again.

As to _execl and _spawnl, those are methods I tried unsuccessfully. I
did try absolute path names by the way. I thought mentioning what I had
tried would be of some interest to whoever wanted to give me some help.

I'm still interested in writing a wrapper for my Java program. If that
is not possible with C++ then feel free to say so.

If this forum is only for discussing pure C++, no OS, no compiler, no
environment and you are not interested in helping me out then please
excuse me for bothering you.

--

Knute Johnson
email s/nospam/knute/
Nov 1 '07 #6

P: n/a
LR wrote:
Knute Johnson wrote:
>Victor Bazarov wrote:
>>Knute Johnson wrote:
I'm trying to write a C wrapper to run a Java program. [..]

You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V

Victor are you the local PITA? There is one in every newsgroup. Did
you not see I was using a C++ compiler to write the program.

I don't think this is a true statement. If you want to write a C
language wrapper or any other kind of C language program, you are going
to use a C compiler. VS 2005 Express is an IDE. Not a compiler.
It has a C++ compiler.
As far as
I know C is still a subset of C++.

I don't believe that is formally true, and depending on what version of
C you are speaking of, it may be less true now than it was.
Go pound sand if you don't want to
be helpful.
I'll agree with my pre-response here.
>Every program has to run on some OS

I know from personal experience that this is not true. I've written
code that ran on machines with no OS.
C++ code?
and if asking how to write a wrapper program

In C.
with a C++ compiler

Doubtful.
I have a C++ compiler, I came to a C++ forum. I think I want to write
it in C++.
>isn't a C++ question then I will quietly go away.

I don't think there's any need to be quiet about it. But I honestly
don't think that you've asked a question about the C++ language. That's
what is on topic in this group. Yes, there are occasional exceptions.

Questions that are about specific compilers, even C++ compilers, are not
generally on topic here.
Describing my environment was only to provide information that
might be necessary to my problem.

I think that you will probably find more help in a group devoted to your
compiler.
>I will happily accept a 'pure' C++ solution.

For reasons that I think are as yet unknown, at least to me,
www.parashift.com is down, but according to a recent post you can see
here, http://groups.google.com/group/comp....d88a0d48be6eec
the most recent copy of the FAQ is here
http://www.cs.technion.ac.il/users/y.../FAQs/c++-faq/

You can read more about where to get help with your particular problem
here
http://www.cs.technion.ac.il/users/y...t.html#faq-5.9

Any assistance is greatly appreciated.

HTH

LR
Thanks very much for the list of newsgroups. That may be the most
helpful hint I've received here.

--

Knute Johnson
email s/nospam/knute/
Nov 1 '07 #7

P: n/a
Knute Johnson wrote:
[..]
If this forum is only for discussing pure C++, no OS, no compiler, no
environment and you are not interested in helping me out then please
excuse me for bothering you.
You're excused.

If you need help with OS, post to the newsgroup dedicated to that OS.

If you need help with your compiler, post to the newsgroup dedicated
to that compiler.

If you need help with the environment... What environment do you mean?
We recycle.

We are interested in "helping you out" if you have a C++ *LANGUAGE*
problem. And I believe we _are_ helping you out by telling you that
you're in the wrong place, otherwise you don't even know you're lost.

See http://www.new-brunswick.net/workshop/c++/faq/ , section 5.
And read the Welcome message 'Shiva' and 'arnuld' have posted here.

All the best!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 1 '07 #8

P: n/a
Victor Bazarov wrote:
Knute Johnson wrote:
>[..]
If this forum is only for discussing pure C++, no OS, no compiler, no
environment and you are not interested in helping me out then please
excuse me for bothering you.

You're excused.

If you need help with OS, post to the newsgroup dedicated to that OS.

If you need help with your compiler, post to the newsgroup dedicated
to that compiler.

If you need help with the environment... What environment do you mean?
We recycle.

We are interested in "helping you out" if you have a C++ *LANGUAGE*
problem. And I believe we _are_ helping you out by telling you that
you're in the wrong place, otherwise you don't even know you're lost.

See http://www.new-brunswick.net/workshop/c++/faq/ , section 5.
And read the Welcome message 'Shiva' and 'arnuld' have posted here.

All the best!

V
Just so I'm clear, you are telling me that C++ has no way of spawning
another program?

Thanks,

--

Knute Johnson
email s/nospam/knute/
Nov 1 '07 #9

P: n/a
Knute Johnson wrote:
Kai-Uwe Bux wrote:
>Knute Johnson wrote:
>>Victor Bazarov wrote:
Knute Johnson wrote:
I'm trying to write a C wrapper to run a Java program. [..]
You could've stopped right there. Neither C nor Java are on topic
in comp.lang.C++. You see, the "plus-plus" is the difference.

Now, if your question is about the compiler or the OS-specific
functions, please RTFM or ask in the newsgroup where those are
topical.

V
Victor are you the local PITA?

Nope. He is a regular who has helped many people in the past.
>>There is one in every newsgroup. Did you not see I was using a C++
compiler to write the program.

What compiler you use is irrelevant for whether your question is topical.
>>As far as I know C is still a subset of C++.

Nit: It is not. There are many legal C programs that are illegal in C++
and many legal C programs that happen to be legal C++, too, but have
different behavior when interpreted as C++ programs. There is, however, a
non-empty intersection of C and C++.
>>Go pound sand if you don't want to be helpful.

Every program has to run on some OS and if asking how to write a wrapper
program with a C++ compiler isn't a C++ question then I will quietly
go away. Describing my environment was only to provide information that
might be necessary to my problem. I will happily accept a 'pure' C++
solution. Any assistance is greatly appreciated.

Your specific question was:
>>I'm using MS Visual C++ Express 2005 for a compiler and I tried
using the _execl and _spawnl functions. These all give me assertion
errors and file not found errors. There is some issue with the path.
Do _execl() and _spawnl() need absolute paths to the files?

A search in my pdf-file of the C++ standard did not find _execl() nor
_spawnl(), and I also did not find it incorporated by reference from the
C standard. This pretty much is is the extend to which your question can
be answered topically in this forum. So in the end, Victor might be right
and you might be better off someplace where _execl() and _spawnl() are
known.

On the other hand, you could just give absolute path names a try and see
whether that cures your problem.

OK, I'm sorry I even mentioned C. I won't do it again.

As to _execl and _spawnl, those are methods I tried unsuccessfully. I
did try absolute path names by the way. I thought mentioning what I had
tried would be of some interest to whoever wanted to give me some help.

I'm still interested in writing a wrapper for my Java program. If that
is not possible with C++ then feel free to say so.
As far as I know, standard C++ has only one method to start another program,
and that is system(). That allows you to run a command, but it does not
even allow you to capture the output in a string or something like that.

Also, as of now now the C++ is not thread-aware, in case that matters.

If this forum is only for discussing pure C++, no OS, no compiler, no
environment
That pretty much sums it up.
and you are not interested in helping me out then please
excuse me for bothering you.
Well, we are interested in helping you. It just so happens that for your
particular problem, the use of non-standard and platform-specific libraries
seems to be the way to go. Those libraries in turn are off-topic here and
hopefully there are other forums where they are being discussed.

On the other hand, whether the lack of support for such tasks in the
standard is a good thing or a bad thing about C++ would be topical here,
but likely to cause a flame war :-)
Best

Kai-Uwe Bux
Nov 1 '07 #10

P: n/a
"Knute Johnson" <no****@rabbitbrush.frazmtn.comwrote in message
news:mk**************@newsfe16.lga...
Victor Bazarov wrote:
>Knute Johnson wrote:
>>[..]
If this forum is only for discussing pure C++, no OS, no compiler, no
environment and you are not interested in helping me out then please
excuse me for bothering you.

You're excused.

If you need help with OS, post to the newsgroup dedicated to that OS.

If you need help with your compiler, post to the newsgroup dedicated
to that compiler.

If you need help with the environment... What environment do you mean?
We recycle.

We are interested in "helping you out" if you have a C++ *LANGUAGE*
problem. And I believe we _are_ helping you out by telling you that
you're in the wrong place, otherwise you don't even know you're lost.

See http://www.new-brunswick.net/workshop/c++/faq/ , section 5.
And read the Welcome message 'Shiva' and 'arnuld' have posted here.

All the best!

V

Just so I'm clear, you are telling me that C++ has no way of spawning
another program?
Standard C++ has no way of spawning another program. Your operating system
might, however, and your compiler writers may include a non standard
function call to spawn another program. But that is not part of the
standard C++ implementation and is specific to your operating
system/compiler. It is done differently on Linux than on Windows than on
Apple OS than on OS400 etc...
Nov 1 '07 #11

P: n/a
On 2007-11-01 22:13, Knute Johnson wrote:
Victor Bazarov wrote:
>Knute Johnson wrote:
>>[..]
If this forum is only for discussing pure C++, no OS, no compiler, no
environment and you are not interested in helping me out then please
excuse me for bothering you.

You're excused.

If you need help with OS, post to the newsgroup dedicated to that OS.

If you need help with your compiler, post to the newsgroup dedicated
to that compiler.

If you need help with the environment... What environment do you mean?
We recycle.

We are interested in "helping you out" if you have a C++ *LANGUAGE*
problem. And I believe we _are_ helping you out by telling you that
you're in the wrong place, otherwise you don't even know you're lost.

See http://www.new-brunswick.net/workshop/c++/faq/ , section 5.
And read the Welcome message 'Shiva' and 'arnuld' have posted here.

All the best!

V

Just so I'm clear, you are telling me that C++ has no way of spawning
another program?
C++ as in "the C++ language", well you could use system() but I
generally discourage the use of that. On the other hand there might be a
number of platform-specific libraries or other third part libraries
which provides the ability to spawning other processes.

On most platforms you can find the POSIX compliant execl(), execv(),
execlp(), and execvp() functions. As you discovered they also exist on
Windows (though MS added an underscore in front). But to get help about
using them you should ask in a group discussing programming on your
platform.

--
Erik Wikström
Nov 1 '07 #12

P: n/a
On 2007-11-01 20:45, Knute Johnson wrote:
LR wrote:
>Knute Johnson wrote:
>>Every program has to run on some OS

I know from personal experience that this is not true. I've written
code that ran on machines with no OS.

C++ code?
Yes, that is what the standard calls a freestanding implementation. One
good example is the Windows kernel, which I have heard is written (at
least partly) in C++.

--
Erik Wikström
Nov 1 '07 #13

P: n/a
LR
Knute Johnson wrote:

Just so I'm clear, you are telling me that C++ has no way of spawning
another program?
Standard C++? Not to my knowlege. And AFAIK, the C++ standard does not
include the functions that you asked about, _execl and _spawnl.

AFAIK, There is no limitation on vendors that suggests that they cannot
implement these functions and ship them in a lib with their compilers.

Perhaps your IDE ships with an extensive help system that contains
references for these platform specific functions and sample code that
will show you how to use it?
Elsethread, you also asked me if I had specifically written code in C++
that ran on a platform without an OS. No. I haven't, but the 2007 draft
standard had this to say on the subject, at least at the time I
downloaded it:

"Two kinds of implementations are defined: hosted and freestanding. For
a hosted implementation, this International Standard defines the set of
available libraries. A freestanding implementation is one in which
execution may take place without the benefit of an operating system, and
has an implementation-defined set of libraries that includes certain
language-support libraries [...]"

So it seems reasonable to me that someone, somewhere is writing C++ code
that will run on a platform with no OS.

Also, may I point out, that an OS is just a program, often largely
written in a language like C or C++, and unless you are deploying the OS
on a VM, the OS will run on a platform that doesn't have an OS.

Thanks,
My pleasure.

LR

Nov 1 '07 #14

P: n/a
Kai-Uwe Bux wrote:
As far as I know, standard C++ has only one method to start another program,
and that is system(). That allows you to run a command, but it does not
even allow you to capture the output in a string or something like that.
I don't need the output, I just want to start the other program. So
could the system() method be used to start my java interpreter?

Could you point me to a copy of the C++ standard or maybe post a snippet
of the docs for system()?

Thanks,

--

Knute Johnson
email s/nospam/knute/
Nov 2 '07 #15

P: n/a
"Knute Johnson" <no****@rabbitbrush.frazmtn.comwrote in message
news:_X**************@newsfe16.lga...
Kai-Uwe Bux wrote:
>As far as I know, standard C++ has only one method to start another
program,
and that is system(). That allows you to run a command, but it does not
even allow you to capture the output in a string or something like that.

I don't need the output, I just want to start the other program. So could
the system() method be used to start my java interpreter?

Could you point me to a copy of the C++ standard or maybe post a snippet
of the docs for system()?
system("myprogram.exe -flags");
Nov 2 '07 #16

P: n/a
Jim Langston wrote:
"Knute Johnson" <no****@rabbitbrush.frazmtn.comwrote in message
news:_X**************@newsfe16.lga...
>Kai-Uwe Bux wrote:
>>As far as I know, standard C++ has only one method to start another
program,
and that is system(). That allows you to run a command, but it does not
even allow you to capture the output in a string or something like that.
I don't need the output, I just want to start the other program. So could
the system() method be used to start my java interpreter?

Could you point me to a copy of the C++ standard or maybe post a snippet
of the docs for system()?

system("myprogram.exe -flags");

That works great. Thanks very much.

--

Knute Johnson
email s/nospam/knute/
Nov 2 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.