• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i use shell32 in my java program  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a java program, i want to call a shell32 and execute it through my java program.Can anyone let me know how to achieve this process?

Thanks&Regards
Jyoti Giri
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.exec() or ProcessBuilder should do it for you.

Not an advanced question. Moving...
[ June 22, 2007: Message edited by: Paul Sturrock ]
 
Jyoti Giri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.I will try it
 
Jyoti Giri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i feel i should write my problem in detail.I have to give a print command from my java program which fires the print command of the printer anf on successfull execution it should print a message.I have written the code but it is not working.If anybody could help,it will be great.

import java.util.*;
import java.io.*;
public class PdfToTif {

/**
* @param args
*/
public static void main(String[] args) {



System.load("C:\\WINNT\\System32\\SHELL32.DLL");

// TODO Auto-generated method stub
try
{
//System.out.println("print");
Runtime rt = Runtime.getRuntime();
//Process proc = rt.exec("print");

Process proc = rt.exec("cmd.exe ");
InputStream is=proc.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String str=null;
while((str=br.readLine())!=null)
System.out.println(str);

//System.out.println(proc);
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);

System.out.println("1");
is=proc.getInputStream();
isr=new InputStreamReader(is);
br=new BufferedReader(isr);
str=null;
while((str=br.readLine())!=null)
System.out.println(str);

System.out.println("2");

} catch (Throwable t)
{
t.printStackTrace();
}
}
}


Thanks and regards,
Jyoti Giri
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does this do (or not) that doesn't match your expectations? I think in this version you're starting cmd.exe which will never complete until you send it an "exit" command. Do you get a couple lines from it like "Microsoft Windows XP [Version 5.1.2600]/n(C) Copyright 1985-2001 Microsoft Corp." and then nothing?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to start new Threads which empty the Process object's two streams, otherwise you can get deadlock. There is an old article here, which explains the problem. It is probably possible to set up more concise coding than used there.

. . . and welcome to the Ranch.

Please use code tags round your quoted code; it makes it easier to read.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!