473,698 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect stdout from java to c

Hi.

I have a strange problem ... I want to create a process and capture stdout :

...
gint std_out;
char* argv[3] = {"/opt/sun-jdk-1.4.2.08/bin/java","hellowor ld",NULL};
//char* argv[3] = {"/usr/bin/du","/",NULL};
g_spawn_async_w ith_pipes("/work/", argv, NULL,
G_SPAWN_CHILD_I NHERITS_STDIN,
NULL, NULL, NULL,
NULL, &std_out,NUL L,
NULL);

gio_stdout = g_io_channel_un ix_new(std_out) ;
g_io_channel_se t_flags(gio_std out, G_IO_FLAG_NONBL OCK, NULL);
g_io_add_watch( gio_stdout, G_IO_IN, printme, (void*)user_dat a);
...

In the case of a "normal" program , e.g. "/usr/bin/du" or anything else,
this works fine, and I can read the programs stdout.
But using the java program i dont get anything at all... !?
helloworld.java just prints "Hello world" using System.out.prin tln.

Can anybody tell me why i cant capture the output of a java program, and
how to fix this ?

Thanks
Nov 15 '05 #1
6 2561
Mazze wrote:
Hi.
(...)
But using the java program i dont get anything at all... !? helloworld.java just prints "Hello world" using System.out.prin tln.

Can anybody tell me why i cant capture the output of a java program, and
how to fix this ?

Thanks


<OT>

Java prints to java console. This question should be answered by Java
people.
Nov 15 '05 #2
Mazze <ma***@no-spam.com> wrote:
Hi.

I have a strange problem ... I want to create a process and capture stdout :

...
gint std_out;
char* argv[3] = {"/opt/sun-jdk-1.4.2.08/bin/java","hellowor ld",NULL};
//char* argv[3] = {"/usr/bin/du","/",NULL};
g_spawn_async_w ith_pipes("/work/", argv, NULL,
G_SPAWN_CHILD_I NHERITS_STDIN,
NULL, NULL, NULL,
NULL, &std_out,NUL L,
NULL);

gio_stdout = g_io_channel_un ix_new(std_out) ;
g_io_channel_se t_flags(gio_std out, G_IO_FLAG_NONBL OCK, NULL);
g_io_add_watch( gio_stdout, G_IO_IN, printme, (void*)user_dat a);
...

In the case of a "normal" program , e.g. "/usr/bin/du" or anything else,
this works fine, and I can read the programs stdout.
But using the java program i dont get anything at all... !?
helloworld.jav a just prints "Hello world" using System.out.prin tln.

Can anybody tell me why i cant capture the output of a java program, and
how to fix this ?


Since literally none of the functions your code calls is standard C,
you won't get a sensible answer in this group. You should try in a
group that deals with Unix programming or Java programming.

Best regards
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc
Nov 15 '05 #3
Thank you, for answering.
Nov 15 '05 #4
Actually, I do have a "serious answer."

One thing you might want to consider is the Java Native Interface (JNI)
binding. (I don't know for sure whether this applies to your
application or not.)

JNI provides an interface between Java and the C programming
environments permitting the mixing of C and Java in a single
application.

Nov 15 '05 #5
ajm
Mazze,

what you are observing here has to do with Java (not C) and how it
handles stdio (the same problem is also encountered if you invoke
processes from within Java and try to capture their output).

best not try to address this here so suggest you take your question to
a Java group (or offline) where you can find out about flushing the
stdio ;)

hth,
ajm.

Nov 15 '05 #6
On Wed, 14 Sep 2005 11:00:16 GMT,
Zara <yo****@terra.e s> wrote:


Java prints to java console. This question should be answered by Java
people.


Java prints to stdout just like any other program. The way to capture this
is independent of wheter the program is done in java or C. It does, however,
depend on some function not defined in the C standard.
Villy
Nov 15 '05 #7

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

Similar topics

0
2412
by: newgene | last post by:
Hi, group, I guess it is a simple question for you, but it puzzles me for a while. I use a wxTextCtrl in my application for output result and any exception msg. I know I can add new msg onto wxTextCtrl by WriteText() method. But I have a function imported from another module and in this function all results are output by "print". I am wondering if I can redirect stdout and stderr into the wxTextCtrl object, so that all output from that...
6
5633
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* . I have tried the simplest method of capturing stdout, stderr via: saveout = sys.stdout sys.stdout = file_obj
1
2340
by: iksrazal | last post by:
Hi all, I've been struggling to make this command work from Java: /usr/bin/mysql c4 --user=root --password=mypass -e "source /home/crissilva/c4.sql" Works fine as shown when run from the shell. Using my Java program I get:
10
21133
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally pointed to? thanks
3
3101
by: mikem76 | last post by:
How do I automatically redirect stdout and stderr when using os.popen2 to start a long running process. If the process prints a lot of stuff to stdout it will eventually stop because it runs out of buffer space. Once I start reading the stdout file returned by os.popen2 then the process resumes. I know that I could just specify > /dev/null when starting the process but I'd like to know if there is a way to start a process using os.popen2...
0
2010
by: danebarney | last post by:
I'm developing a Windows CE 5.0 app using C# and I need to call a child process and then capture its stdout into a window. The solutions I've read online for doing this involve either using the CreateProcess(), a Win32 API function which isn't easily accessible in a C# app, or using the System.Diagnostics.Process class which seems to only have stdout redirection capabilities in Win32, but not CE. So what are my best options?
10
8413
by: Jef Driesen | last post by:
I wrote a program that writes a large amount of information to stdout (and stderr). When run from the commandline, this output either appears on the console window (the default) or can be redirected to a file by means of the freopen() function: freopen ("logfile.txt", "w", stdout); But I would like to have the output on the console AND a logfile. Is this possible (without using an extra program like 'tee')?
0
921
by: Neal Becker | last post by:
Is there a simple way to use a 'with' statement to redirect stdout in a block?
0
8678
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8899
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
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
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.