swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Swftools-common] calling pdf2swf from java


From: Andreas Haufler \(scireum\)
Subject: RE: [Swftools-common] calling pdf2swf from java
Date: Mon, 23 Nov 2009 14:43:15 +0100

Dear Stefan,

 

you need to read both, stdout and stderr from the started Process. Otherwise it might block. Try searching this list, I’ve already posted some example code how to do this (Basically start 2 threads and read both streams).

 

It looks roughly like this:

 

            StringBuffer logger = new StringBuffer();

            try {

                  Process p = Runtime.getRuntime().exec(command);

                  StreamEater errEater = StreamEater.eat(p.getErrorStream(), logger);

                  StreamEater outEater = StreamEater.eat(p.getInputStream(), logger);

                  try {

                        p.waitFor();

                  } catch (InterruptedException e) {

                        throw new ExecException(e, logger.toString());

                  }

                  return logger.toString();

            } catch (IOException e) {

                  throw new ExecException(e, logger.toString());

            }

 

StreamEater is a Runnable which looks like this:

            public void run() {

                  try {

                        InputStreamReader isr = new InputStreamReader(stream);

                        BufferedReader br = new BufferedReader(isr);

                        String line = br.readLine();

                        while (line != null) {

                             logger.append(line);

                             logger.append("\n");

                             line = br.readLine();

                        }

                        br.close();

                  } catch (IOException e) {

                        logger.append(Tools.asString(e));

                  }

            }

 

Regards

Andy

 

 

freundliche Grüße
scireum - Ein Unternehmen der TTI GmbH

i.A. Andreas Haufler
Projektleiter scireum

-------------------------------------------------------------------------------------------------------

TTI GmbH - TGU scireum, Friedrichstr. 8, 70736 Fellbach

Tel: (0711) 69394632  -  E-Mail:   address@hidden
Fax: (0711) 69394635  -  Internet: http://www.scireum.de

 

TTI GmbH - Zentrale, Nobelstr. 15, 70569 Stuttgart

Geschäftsführer: Prof. Dr.-Ing. Bernd Bertsche, Elgar Rödler

Amtsgericht Stuttgart, HRB 19455

 

From: address@hidden [mailto:address@hidden On Behalf Of Canda Stefan
Sent: Monday, November 23, 2009 12:43 PM
To: address@hidden
Subject: [Swftools-common] calling pdf2swf from java

 

Hi,

I have a problem when calling pdf2swf from java. When i converting bigger file it freeze, but when i make it from command line it works fine.

Some ideas?

 

Here is the code i use:

try

{

Process proc = Runtime.getRuntime().exec(command.toString()); 

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()) ); 

  

String message = "SC"; 

writer.write(message, 0, 1);

logger.debug("\n\twaiting while convert finish --->"+new Date());

Timer timer = new Timer();

timer.schedule(new InterruptScheduler(Thread.currentThread()), TIMEOUT);

try

{

                        proc.waitFor();

                        logger.debug("\n\tconvert done --->"+new Date());

                        System.out.println("\n\thotovo..."); 

                        return saveFilename;

}

catch (InterruptedException e)

{

                        // Stop the process from running

                        logger.debug("\n\ttimeout expired --->"+new Date());

                         proc.destroy();

                         return "errorPdf2swf";

}

finally

{

                         // Stop the timer

                         timer.cancel();

}

catch (Exception e)

              e.printStackTrace(); 

                   

return null;

 

 

Thanks for help

 

Stetka

Trask solutions  |  www.trask.cz

Klostermanova 690/15

460 01 Liberec, Česká republika

T +420 725 722 990 F +420 220 414 127

enabling innovation 

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]