Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:17:11+00:00 2026-06-09T14:17:11+00:00

Please move down to the 2nd update. I didn’t want to change the previous

  • 0

Please move down to the 2nd update. I didn’t want to change the previous context of this question.

I’m using wkhtmltoimage from a Java app.

The standard way of using it is – path-to-exe http://url.com/ image.png.

According to their docs, if we write a - instead of an input URL, the input shifts to STDIN.

I’m starting the process using ProcessBuilder –

ProcessBuilder pb = new ProcessBuilder(exe_path, " - ", image_save_path);

Process process = pb.start();

Now I’m unable to figure out how to pipe an input stream to this process.

I have a template file read into a DataInputStream, and I’m appending a string at the end:

DataInputStream dis = new DataInputStream (new FileInputStream (currentDirectory+"\\bin\\template.txt"));
byte[] datainBytes = new byte[dis.available()];
 dis.readFully(datainBytes);
 dis.close();

 String content = new String(datainBytes, 0, datainBytes.length);

 content+=" <body><div id='chartContainer'><small>Loading chart...</small></div></body></html>";

How do I pipe content to the STDIN of the process?

UPDATE—

Following the answer by Andrzej Doyle:

I’ve used the getOutputStream() of the process:

ProcessBuilder pb = new ProcessBuilder(full_path, " - ", image_save_path);

    pb.redirectErrorStream(true); 

    Process process = pb.start();         

    System.out.println("reading");

    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

    bw.write(content);

Doing so gives an error saying:

Exception in thread "main" java.io.IOException: The pipe has been ended

2nd UPDATE——–

The current code block is as such:

    try {
        ProcessBuilder pb = new ProcessBuilder(full_path, "--crop-w", width, "--crop-h", height, " - ", image_save_path);
        System.out.print(full_path+ "--crop-w"+ width+ "--crop-h"+ height+" "+ currentDirectory+"temp.html "+ image_save_path + " ");
        pb.redirectErrorStream(true); 

        Process process = pb.start(); 
        process.waitFor();
        OutputStream stdin = process.getOutputStream();

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
// content is the string that I want to write to the process.

        writer.write(content);
        writer.newLine();  
        writer.flush();
        writer.close();


    } catch (Exception e) {
        System.out.println("Exception: " + e);
        e.printStackTrace();
    }

Running the above code gives me an IOException: The pipe is being closed.

What else do I need to do to keep the pipe open?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:17:13+00:00Added an answer on June 9, 2026 at 2:17 pm

    Remove the whitespace from " - " — the normal whitespaces are removed by the shell parser, but here in the ProcessBuilder, it’s interpreted as the (literal) filename beginning and ending with a whitespace.

    (Actually looking at the process’s output as Peter suggested would probably have told you so…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please feel free to move this to meta/superuser if this is the wrong place.
Please take a look at this screenshot first: I would like to move the
I want my Views to move horizontally in tandem with our finger moving. Please
I am using a drop down list as a navigation option to move between
Can anyone please tell me how to move table rows up and down through
I want to draw the track of mouse when it down and move. I
Can anyone please tell me how to move file(s) into a dir in PHP?
Please help me somebody to convert unicodestring into string This is how i am
Please i need help, this code below works fine on my localhost, php5.3+ but
I used mouseup/down/move to manually implement jQuery.draggable functionality. Everything was working fine until I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.