• Post Reply Bookmark Topic Watch Topic
  • New Topic

Open the notepad with some text at runtime

 
Thyagarajan Ramanujam
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to open the notepad at runtime and the notepad should contain the text which i pass. The code I tried to achieve this is



String str = "hai";
Process p = Runtime.getRuntime().exec("notepad");
p.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(p.getOutputStream());
bos.write(source.getBytes());

The notepad is opened but the text is not written in it.

Urgent. Any help is appreciated.

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can pass text into notepad from the command line. Maybe you can write the text to a file, and then pass the file name to notepad. Make sure notepad can open files you specify on the command line first.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kludgy, and not worth doing for anything longer than "hai",
but robot.keyPress/Release will do it
 
Thyagarajan Ramanujam
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any sample code for this?

Thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you already have the Runtime.exec call. It's just a matter of adding a file name (IF that works, about which I'm not sure. But that's easy to test on a Windows command line).
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works.. create a sample .txt file in desktop called as "ONE.txt".

In Command prompt

if we say

notepad ONE.txt

The notepad comes up with the one.txt file in it.. But make sure the directory should match.
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a commandline option for notepad to pass it some text?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!