I never noticed this before, but when I run an external program through
Runtime, like this:
Runtime rt = Runtime.getRunt ime();
System.out.prin tln("Running external command: " + sCommand);
try {Process p = rt.exec(sComman d);} catch (Exception e)
{System.out.pri ntln("Cannot Run Command: " + sCommand + ", Error: " + e);}
the external command is asynchronous -- completely spun off as a separate
thread or process. Is there any way to avoid this? I have an external
command that creates a number of files. Once they're created by the other
program, I want to use them in my system. Is there a way to wait on a
Runtime object until the program finishes running? Or a way to check on it
and see if it is completed?
I figure I could also add in a loop to wait until the Runtime commands
create certain files (or alter others), but I can forsee more complications
with that than with some way to wait until the command is done.
I searched the Java SDK docs, but can't find methods in Runtime that will
help.
Thanks for any help.
Hal 4 24529
Hal Vaughan wrote:
[...] Is there a way to wait on a Runtime object until the program finishes running? Or a way to check on it and see if it is completed?
[...] I searched the Java SDK docs, but can't find methods in Runtime that will help.
See the Javadoc for java.lang.Proce ss.
Process p = Runtime.exec("f oo");
int exitCode = p.waitFor();
--
Jonas Kongslund
Jonas Kongslund wrote: Hal Vaughan wrote:
[...] Is there a way to wait on a Runtime object until the program finishes running? Or a way to check on it and see if it is completed? [...] I searched the Java SDK docs, but can't find methods in Runtime that will help.
See the Javadoc for java.lang.Proce ss.
Process p = Runtime.exec("f oo"); int exitCode = p.waitFor();
That's exactly what I need. I started w/ Java a few months ago and have
NEVER used OOP or any kind of programming that deals with classses or
objects before (I used to program on an Apple //e in Assembler!), so I'm
still getting used to working with different classes and objects. While it
makes perfect, simple, sense to check the object created by the command,
I'm still not used to thinking that way.
Thanks. This helps with the immediate problem, but also helps me a little
with getting used to how Java "thinks" and how to use objects.
Hal
Hal Vaughan <ha*@thresholdd igital.com> wrote in message news:<DVmpb.913 55$Tr4.252674@a ttbi_s03>... I never noticed this before, but when I run an external program through Runtime, like this:
Runtime rt = Runtime.getRunt ime(); System.out.prin tln("Running external command: " + sCommand); try {Process p = rt.exec(sComman d);} catch (Exception e) {System.out.pri ntln("Cannot Run Command: " + sCommand + ", Error: " + e);} Hal
hi
Process p = rt.exec(sComman d);
p. waitFor();
System.out.prin tln("program exited with : " +p.exitValue()) ;
is it this you are looking for ?
this will wait untill your command is finished executing & then you
can also access its exit value , if required
regards
amey
Hal Vaughan <ha*@thresholdd igital.com> wrote in message news:<DVmpb.913 55$Tr4.252674@a ttbi_s03>...
[snipped...] I searched the Java SDK docs, but can't find methods in Runtime that will help.
Process.waitFor () looks like it may do the job.
-FISH- ><> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Avnish Midha |
last post by:
Does the Runtime.exec() method support parameters from non-native
locales i.e. does it really support the entire unicode range of
characters in the parameters. I am trying ot invoke a C++ application
(exe) using the exec() method. The C++ application is unicode enabled
i.e. it can accept wide chars as command line arguments. I am passing
UTF-16 java String parameters to the Runtime.exec() function, but when
these parameters are checked in...
|
by: TiscaliNews |
last post by:
Hi,
I have a tool that listen on a tcp/ip port and when a message arrives, it is
printed to stdout. This tool is started using Runtime.exec using a wrapper
to catch the output of the tool. The wrapper is started and accessed from a
jython script.
Problem: The output from the tool (catched by the wrapper and displayed in
jython) does not come always available at the time it is expected. The
wrapper receives the output from the tool in...
|
by: Hal Vaughan |
last post by:
I've been using Runtime.exec() like this:
Runtime rt = Runtime.getRuntime();
try {Process p = rt.exec("MyCommand.bat");} catch (Exception e) {do stuff}
When I start my Java classes, I start them with a batch file that changes to
my apps home directory. I've tried exec() with a full pathname (which
seems to have problems on Windows if it has spaces in it, but I'm not sure
if that's really the problem), with just the simple short batch...
|
by: Anastasios Kotsikonas |
last post by:
Hi all,
here's the situtation:
1) JDK 1.4.2_02 & Tomcat 4.1.x (no difference with any 1.4.x)
2) Multiple threads (testing with 5) access non-sync methods in a single instance of a class
with ThreadLocals as appropriate (turns out using different instances
of the class sans ThreadLocal doesn't change anything)
|
by: uwnewsgroup |
last post by:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and
try to
get its standard output by using Process.getOutputStream(), it blocks
forever. I tried
it using Java 1.4 and the results are the same on SunOS 5.8, Redhat8.0,
cygwin.
I read relevant articles and find the reason is that the output of the
process exceeds the
buffer allocated for that process. So can I adjust the buffer size (on any
| |
by: James Goldwater |
last post by:
I have a situation where I actually _do_ want the command window to
show after a runtime.exec() call. (Although we pipe stout/stdin to
our own logging mech, the program needs to be able to trap Ctrl-C
keystrokes). Our application is launched by javaw.
In Java 1.3.1, this behaviour was present (and much resented it looks
like) but in 1.4+ Sun have 'fixed' it, and the dos window no longer
pops up on a...
|
by: chenthil |
last post by:
In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other batch file start.bat.
The piece of code which I am using is:
public static void ExecuteScripts(){
try {
\\Start the first batch program call.bat
Process p = Runtime.getRuntime().exec("cmd /c start .\\scripts\\call.bat");
...
|
by: angelotti |
last post by:
Hi everyone , i am banging my head over the following problem for a couple of weeks now: i am starting a MyProg.exe(a simple C app) from a java class with .exec() as a system process(not in it's own console) and i would like to communikcate with its I/O before it is finished. I don't have this issue if for instance i am starting another java app.
The problem i meet is that the I/O is bloked while the process is being executed.When i terminate...
|
by: madhawa84 |
last post by:
i have written a simple java program using a Runtime.exec() .i was able to run my java program in the pc which i used to compiled the code.but when i migrate my program in to an another machine having the same OS(windows XP),my code did not worked .there was not any signs of execution of my code.why this was occured .explain me.
|
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,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |