473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Calling foreign executables

How can i call some other program from java application?

let say i want to call iexplorer('iexplore' from command line)...
thnx
Jul 17 '05 #1
2 3248
Hrvoje Somun wrote:
How can i call some other program from java application?

let say i want to call iexplorer('iexplore' from command line)...
thnx


Maybe this could help you as an example, but I would suggest to do some more
eductional reading on java ;-)

import Java.lang.*;
import Java.io.*;

public class RuntimeExecTest {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "Notepad.exe",
"D:\\TEMP\\Test.txt" };
try {
Process child = rt.exec(callAndArgs);
child.waitFor();
System.out.println("Process exit code is:
" + child.exitValue());
}
catch(IOException e) {
System.err.println(
"IOException starting process!");
}
catch(InterruptedException e) {
System.err.println(
"Interrupted waiting for process!");
}
}
}

--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
Jul 17 '05 #2

"Hrvoje Somun" <hr****************@zg.tel.hr> wrote in message
news:br**********@sunce.iskon.hr...

How can i call some other program from java application?

let say i want to call iexplorer('iexplore' from command line)...
thnx


You may care to try the code below.

I hope this helps.

Anthony Borla

// ---------------------------------------------

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class LaunchIE
{
public static void main(String[] args)
{
if (args.length < 1)
{
System.err.println("Usage: java LaunchIE filename");
System.exit(1);
}

try
{
viewFile(new File(args[0]));
}

catch (FileNotFoundException e)
{
System.err.println("File could not be located, or does not exist");
}

catch (IOException e)
{
System.err.println("File could not be opened");
}
}

// Win32-specific Code
public static void viewFile(File file)
throws FileNotFoundException, IOException
{
if (!file.isFile())
throw new FileNotFoundException();

StringBuffer cmd =
new StringBuffer("rundll32 SHELL32.DLL,ShellExec_RunDLL ");

cmd.append(file.getAbsolutePath());

Runtime.getRuntime().exec(cmd.toString());
}
}

// --------------------------------------------

Jul 17 '05 #3

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

Similar topics

8
by: Patrick Useldinger | last post by:
Hi all, I am looking for beta-testers for fdups. fdups is a program to detect duplicate files on locally mounted filesystems. Files are considered equal if their content is identical,...
1
by: Chandra Mohan | last post by:
Hi All, I have a requirement of calling a Executable from SQL Server. I know we can use - EXEC @result = Master..xp_cmdshell @<command_string> However I want to get the return value (int)...
4
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which...
6
by: Marlene Arauz Martin | last post by:
Hello, How's everybody??? I have an aspx. page that is calling an executable,....like this... System.Diagnostics.ProcessStartInfo psi= new System.Diagnostics.ProcessStartInfo();...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
1
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss...
2
by: Richard B | last post by:
I added a .NET dll as a reference to my new .NET dll. When I went to build, I received error "Unable to emit assembly: Referenced assembly 'CrystalReport' does not have a strong name". ...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
1
by: Water Cooler v2 | last post by:
I have a Windows Service I am writing in C# and a set of, let us say three, other executables written in C# (mostly console applications). I want that the Windows Service must do so every few...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.