0

I started to learn about processes in Java, so following question popped up. Let's say that I have some text data stored in variable. I want to start notepad.exe by starting a new process and somehow to pass this text data to it, so it can be shown. Here is some basic snippet that I found. How can I change it, so it performs feeding of notepad with text stored in variable ? Also, can I make generalization and assume that I have some .pdf file completely loaded in RAM. Can I start new process in which I will invoke some PDF reader and feed it with .pdf data stored in RAM? Thanks!

p.s. I don't want to store data into file (or cache) and then perform feeding of application from it.

   try {
        // create a new process
        System.out.println("Creating Process...");
        Process p = Runtime.getRuntime().exec("notepad.exe");

        // get the output stream
        OutputStream out = p.getOutputStream();

        // close the output stream
        System.out.println("Closing the output stream...");
        out.close();
  } catch (Exception ex) {
        ex.printStackTrace();
  }
Darian Pudic
  • 45
  • 2
  • 10
  • 2
    Notepad isn't possible I'm afraid unless it exposes an API. All you could do is to get it to open a specific file probably. I'm going to take a wild guess that Notepad can't even read from stdin – g00se Oct 15 '22 at 13:28
  • 1
    A process must be able to take input / have an InterProcessCommunication API. You can probably create a text file first, then open notepad with that file but you won't be able to send commands that way. Windows has APIs to control the system, those could be used to control notepad but you'd have a far easier time using something like AutoIt, AutoHotkey, .. since tools like that have functionality to send keystrokes etc to other applications using all those Windows APIs – zapl Oct 15 '22 at 14:06

0 Answers0