Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

how can i use shell32 in my java program

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help.I will try it
 
Jyoti Giri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 75836
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic