Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Unable to write in notepad

Reply
Thread Tools

Unable to write in notepad

 
 
Pranjal Jain
Guest
Posts: n/a
 
      05-22-2008
Hi All
I am trying to write the data in the notepad. But I the data going in it
is wrong. The output which I am getting in the notepad is



!FA

The code I used is as follows:

"
# Require the win32ole library:
require 'win32ole'
# Create an instance of the Wscript Shell:
wsh = WIN32OLE.new('Wscript.Shell')
# Try to activate the Notepad window:
if wsh.AppActivate('Notepad')
sleep(1)
# Enter text into Notepad:
wsh.SendKeys('Ruby{TAB}on{TAB}Windows{ENTER}')
# ALT-F to pull down File menu, then A to select Save As...:
wsh.SendKeys('!F')
wsh.SendKeys('A')
sleep(1)
if wsh.AppActivate('Save As')
wsh.SendKeys('c:\temp\filename.txt{ENTER}')
sleep(1)
# If prompted to overwrite existing file:
if wsh.AppActivate('Save As')
# Enter 'Y':
wsh.SendKeys('Y')
end
end
# Quit Notepad with ALT-F4:
wsh.SendKeys('%{F4}')
end

"

One more interesting thing is that here I am able to write the value in
the notepad which is already opened. if the notepad is not opened, then
ruby just intepret the script & does not write the output.

Please suggest the solution for this.
Thankx in advance
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Heesob Park
Guest
Posts: n/a
 
      05-22-2008
Hi,

2008/5/22 Pranjal Jain <>:
> Hi All
> I am trying to write the data in the notepad. But I the data going in it
> is wrong. The output which I am getting in the notepad is
>
>
>
> !FA
>
> The code I used is as follows:
>
> "
> # Require the win32ole library:
> require 'win32ole'
> # Create an instance of the Wscript Shell:
> wsh = WIN32OLE.new('Wscript.Shell')
> # Try to activate the Notepad window:
> if wsh.AppActivate('Notepad')
> sleep(1)
> # Enter text into Notepad:
> wsh.SendKeys('Ruby{TAB}on{TAB}Windows{ENTER}')
> # ALT-F to pull down File menu, then A to select Save As...:
> wsh.SendKeys('!F')
> wsh.SendKeys('A')
> sleep(1)
> if wsh.AppActivate('Save As')
> wsh.SendKeys('c:\temp\filename.txt{ENTER}')
> sleep(1)
> # If prompted to overwrite existing file:
> if wsh.AppActivate('Save As')
> # Enter 'Y':
> wsh.SendKeys('Y')
> end
> end
> # Quit Notepad with ALT-F4:
> wsh.SendKeys('%{F4}')
> end
>
> "
>
> One more interesting thing is that here I am able to write the value in
> the notepad which is already opened. if the notepad is not opened, then
> ruby just intepret the script & does not write the output.
>
> Please suggest the solution for this.
> Thankx in advance


Here is a working code:

# Require the win32ole library:
require 'win32ole'
# Create an instance of the Wscript Shell:
wsh = WIN32OLE.new('Wscript.Shell')
if not wsh.AppActivate('Notepad')
wsh.Run('Notepad')
sleep(1)
end
# Try to activate the Notepad window:
if wsh.AppActivate(Notepad)
sleep(1)
# Enter text into Notepad:
wsh.SendKeys('Ruby{TAB}on{TAB}Windows{ENTER}')
# ALT-F to pull down File menu, then A to select Save As...:
wsh.SendKeys('%FA')
sleep(1)
wsh.SendKeys('c:\temp\filename.txt{ENTER}')
sleep(1)
# If prompted to overwrite existing file:
if wsh.AppActivate('Save As')
# Enter 'Y':
wsh.SendKeys('Y')
end
# Quit Notepad with ALT-F4:
wsh.SendKeys('%{F4}')
end


Regards,

Park Heesob

 
Reply With Quote
 
 
 
 
Pranjal Jain
Guest
Posts: n/a
 
      05-22-2008
Hi
I am sorry
it worked for me sooner after I posted the question.I had used the same
code which u mentioned.

But there is another problem I am facing.
For running the the script the notepad should be opened before I execute
the script.

I dnt want to keep any notepad open before I start running the script.
Can u suggest how I can overcome this problem


Heesob Park wrote:
> Hi,
>
> 2008/5/22 Pranjal Jain <>:
>> "
>> wsh.SendKeys('!F')
>> end
>> Please suggest the solution for this.
>> Thankx in advance

>
> Here is a working code:
>
> # Require the win32ole library:
> require 'win32ole'
> # Create an instance of the Wscript Shell:
> wsh = WIN32OLE.new('Wscript.Shell')
> if not wsh.AppActivate('Notepad')
> wsh.Run('Notepad')
> sleep(1)
> end
> # Try to activate the Notepad window:
> if wsh.AppActivate(Notepad)
> sleep(1)
> # Enter text into Notepad:
> wsh.SendKeys('Ruby{TAB}on{TAB}Windows{ENTER}')
> # ALT-F to pull down File menu, then A to select Save As...:
> wsh.SendKeys('%FA')
> sleep(1)
> wsh.SendKeys('c:\temp\filename.txt{ENTER}')
> sleep(1)
> # If prompted to overwrite existing file:
> if wsh.AppActivate('Save As')
> # Enter 'Y':
> wsh.SendKeys('Y')
> end
> # Quit Notepad with ALT-F4:
> wsh.SendKeys('%{F4}')
> end
>
>
> Regards,
>
> Park Heesob


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      05-22-2008
Hi,

2008/5/22 Pranjal Jain <>:
> Hi
> I am sorry
> it worked for me sooner after I posted the question.I had used the same
> code which u mentioned.
>
> But there is another problem I am facing.
> For running the the script the notepad should be opened before I execute
> the script.
>
> I dnt want to keep any notepad open before I start running the script.
> Can u suggest how I can overcome this problem
>

I guess you did not try my code.
Following code is included for the opening notepad:

if not wsh.AppActivate('Notepad')
wsh.Run('Notepad')
sleep(1)
end

Regards,

Park Heesob

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot launch simple applications (notepad, java) using Apache and PERL(CGI) JDS Perl 4 11-11-2008 08:50 PM
Can I write text to a notepad and save the file through ruby Anukul Singhal Ruby 3 03-21-2008 12:59 AM
Notepad 2 write first HTML...now what???? help fredcromer Computer Support 7 05-05-2004 07:40 PM
Notepad to write my 1st webspace HTML, fredcromer Computer Information 3 05-04-2004 02:08 PM
Call Notepad from aspx Tim S. ASP .Net 2 07-14-2003 06:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57