473,549 Members | 2,750 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling "java from C dll" (system command??)

Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

Or do I have to use some JNI interface.?

Jul 21 '06 #1
11 2709
On 2006-07-21, jo*****@hotmail .com <jo*****@hotmai l.comwrote:
Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?
No. That's a either a string literal or a syntax error, depending on
whether you preserve your quotes.
Or do I have to use some JNI interface.?
I don't know. Unfortunately, I can't think of who /would/ know, so I
can't redirect you.
Jul 21 '06 #2
jo*****@hotmail .com wrote:
Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?
You can, but whether it works depends on things outside the C language.
Or do I have to use some JNI interface.?
You may be able to do that as well.

The best solution will depend on what you are trying to achieve, and you
would be better off discussing it in a group dedicated to your
implementation or, depending on what they consider topical, a Java group
than on comp.lang.c (I've no idea about comp.lang.java. programmer).

Follow-ups set, since solving the OPs problem will involve things beyond
the scope of standard C and so is off topic for comp.lang.c
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jul 21 '06 #3
jo*****@hotmail .com wrote:
Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

Or do I have to use some JNI interface.?
There is a very simple way to verify this:

1) open a command shell
2) type in that command shell
java -jar filename

If that works, then the C function call
system("java -jar filename");

will work too. Note the correct quotes, and not
as you typed...

jacob
Jul 21 '06 #4
<jo*****@hotmai l.comwrote
Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

Or do I have to use some JNI interface.?
System is the portable, ANSI C way of doing it.
Usually portable, ANSI methods are best, but "system" is often an exception.
There might be a better way that doesn't rely on your user having all his
paths set up correctly.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
Jul 22 '06 #5
jacob navia <ja***@jacob.re mcomp.frwrote:
jo*****@hotmail .com wrote:
Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

There is a very simple way to verify this:

1) open a command shell
2) type in that command shell
java -jar filename

If that works, then the C function call
system("java -jar filename");

will work too.
This is far from guaranteed. It's a start; but it's not enough for
certainty.
Note the correct quotes, and not as you typed...
True.

Richard
Jul 24 '06 #6
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.frwrote:

>>jo*****@hotma il.com wrote:
>>>Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

There is a very simple way to verify this:

1) open a command shell
2) type in that command shell
java -jar filename

If that works, then the C function call
system("java -jar filename");

will work too.


This is far from guaranteed. It's a start; but it's not enough for
certainty.

>>Note the correct quotes, and not as you typed...


True.

Richard
The standard says about the system function:
< quote>
If string is a null pointer, the system function determines whether the
host environment has a command processor. If string is not a null
pointer, the system function passes the string pointed to by string to
that command processor to be executed in a manner which the
implementation shall document
< end quote >

I do not see how that method above could fail, given that java is
installed in the machine and is in the path...

Jul 24 '06 #7
On Mon, 24 Jul 2006 20:46:56 +0200, in comp.lang.c , jacob navia
<ja***@jacob.re mcomp.frwrote:
>Richard Bos wrote:
>jacob navia <ja***@jacob.re mcomp.frwrote:

>>>jo*****@hotm ail.com wrote:

Can I use this line inside C program "system(jav a -jar <jarfilename> )"
to run a java program from C?

There is a very simple way to verify this:

1) open a command shell
2) type in that command shell
java -jar filename

If that works, then the C function call
system("java -jar filename");

will work too.


This is far from guaranteed. It's a start; but it's not enough for
certainty.

>>>Note the correct quotes, and not as you typed...


True.

Richard

The standard says about the system function:
< quote>
If string is a null pointer, the system function determines whether the
host environment has a command processor. If string is not a null
pointer, the system function passes the string pointed to by string to
that command processor to be executed in a manner which the
implementati on shall document
< end quote >

I do not see how that method above could fail, given that java is
installed in the machine and is in the path...
For all sorts of reasons which are offtopic here, such as environment
inheritance / cloning, permissions, security configuration, etc etc.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 24 '06 #8
Mark McIntyre wrote:
>>
The standard says about the system function:
< quote>
If string is a null pointer, the system function determines whether the
host environment has a command processor. If string is not a null
pointer, the system function passes the string pointed to by string to
that command processor to be executed in a manner which the
implementatio n shall document
< end quote >

I do not see how that method above could fail, given that java is
installed in the machine and is in the path...


For all sorts of reasons which are offtopic here, such as environment
inheritance / cloning, permissions, security configuration, etc etc.
Those reasons would make it fail within the command shell also!
If you have the wrong permissions, for instance, it should
not work in the command shell!!!

What I want to say is that IF the command works within a
command shell, it MUST work within the system() function,
unless the user or the program is impersonating somebody else.
Jul 25 '06 #9
jacob navia <ja***@jacob.re mcomp.frwrites:
Mark McIntyre wrote:
[...]
[attribution lost]
>>I do not see how that method above could fail, given that java is
installed in the machine and is in the path...
For all sorts of reasons which are offtopic here, such as
environment
inheritance / cloning, permissions, security configuration, etc etc.

Those reasons would make it fail within the command shell also!
If you have the wrong permissions, for instance, it should
not work in the command shell!!!

What I want to say is that IF the command works within a
command shell, it MUST work within the system() function,
unless the user or the program is impersonating somebody else.
Not correct. I can think of a number of other reasons why a system()
command might fail even if the same command string works in a command
shell.

<OT>
Just a few examples (many of these are Unix-specific):

The user's default shell could be different from the one used by
system(). The program's environment might be different from the
user's environment, perhaps because the program changed it, perhaps
for some other reason. The program might be executed from a cron job,
which has a limited default environment, including a relatively short
$PATH. The command might be an alias or shell function, which would
be invisible to system(). The command might be setuid, i.e.,
impersonating someone else, a possibility you acknowledged above, but
not in your previous followup.
</OT>

I presume there are similar possibilities for other systems.

The point is that the standard makes very few guarantees about how
system() behaves, and assuming, perhaps based on your own experience,
that there are additional guarantees in real life is unwise.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2030
by: Nicolas Fleury | last post by:
Hi, How can I know if a system command doesn't exist? All the ways I have tried behave like if the system command was existing but returning one. I don't want to sound provocative, but open in Perl returns an error in a command doesn't exist, so I'm sure we could have an exception in the same case for popen in Python? Thx and Regards, ...
15
7900
by: Sokar | last post by:
Hello, I am writing a script which is using the system() command. In the script the system command invokes an encryption with system("gpg -f file.txt"). The problem comes when the script is required to perform this operation on different files which the user selects via another function. The name of the filename is stored in a variable...
6
1807
by: jsw_nz | last post by:
Helo, my first post here.... I am trying to run an agent application that converts and imports two tables from MS Access into mySql. (Intelligent Converters - Access2mySql) I have run similar scripts to do mysql dumps using the system function. Not sure if the paths included in the parameters are correct: <?php function import_data() {
1
2935
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. I want to trap the key combo and exit (somewhat) gracefully if the user decides to abort the program. I am using os.system for the system call, ...
3
2633
by: pavi | last post by:
Hi, I am using system command to execute a shell script in a C program. Usage system("sh file"). There are situations where the file may be empty. But execution gets hung if the file is empty. What might be the problem. Regards, Praveen Kumar A.S
1
1454
by: roocell | last post by:
I'm running a system command on my server system(copy file.txt lpt1); to print a file to lpt1. This works fine on an XP machine and also works fine on the vista machine if i do it manually from a DOS prompt. I'm guessing it has something to do with User Acess Control (UAC) and elevating the PHP script or something.
8
10340
by: jkeith07 | last post by:
Ok so ive reached the end of my knowledge and have tried to find out how to do it and just plain dont understand it. I have a system call: system("db2cmd.exe \"db2 connect to vop9 user joebloggs using joesPassword&&db2 LOAD FROM \"d:\\vop9\\records_test.csv\" OF DEL MODIFIED BY COLDEL; METHOD P (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,...
4
2684
by: boriq | last post by:
Hi, I'm using in my script command os.system('command') on Windows XP. Each time the os.system command is used, python opens an empty ms-dos command window (the black one) and then closes it. So when in one script the os.system command 50 times is used, I see 50 black windows. Is there a way of how to suppress this unnecessary command...
0
7551
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7477
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7750
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7991
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1971
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.