Jump to content

Echo variable output to notepad.exe


Bash99
 Share

Recommended Posts

I'm new to scripting and find it best by learning from others examples.  I generally do this with small snippets of code as it tends to be a lil easier trying to figure out what makes what happen.  My question is this...I have what I think is a simple variable defined and I want to output the info that the variable contains to notepad.  I have tried all sorts of ways looking at others code but I can't seem to find the right combination.  Here it is in really basic form.  I also believe that If I can see how this works, I can then move forward with defining the variable later on with what I would cosnider to be more complex ways such as an input box etc...

Global $nU = "Name"

 

RunWait(@ComSpec & " /c " & 'echo "$nU" > C:basicinfo.txt', "", @SW_HIDE)

 

Any help would be greatly appreciated.  I have also looked around the forums and Googled this and I can't seem to find something at my level to better understand this.  The link below is one of those items I tried to use as a reference but I just couldn't figure it out.

https://www.autoitscript.com/wiki/Snippets_(_CMD_)

Thank you.

bash99

Link to comment
Share on other sites

  • Moderators

Look at the examples in the help file for ShellExecute and ControlSend for more:

$sVar = "Name"

ShellExecute("Notepad.exe")
WinWait("[CLASS:Notepad]", "")
ControlSend("[CLASS:Notepad]", "", "Edit1", $sVar)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Global $nU = "Name"
 
FileWrite('C:\basicinfo.txt', $nu)

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ok. While I thank you for your input, I'll say based on the response, I don't need to open notepad. Which is why I have @SW_HIDE.  I don't need to wait for notepad to open and I don't need to send anything to an open notepad window.  I'm sorry if I what I described was inaccurate but I don't see where I can make it clearer.  Let me try it another way.  Using the information originally stated can anyone provide me with the correct syntax for the RunWait(@Comspec line below because I can't figure it out.  When I run it, it puts "$nU" without the quotes into the text file basicinfo.txt.  What I want is the code to put the variable info "name" without quotes into the basicinfo.txt file.  I hope this is a better way to describe it.

Global $nU = "Name"

RunWait(@ComSpec & " /c " & 'echo "$nU" > C:basicinfo.txt', "", @SW_HIDE)

Link to comment
Share on other sites

That's exactly what my snippet does. But if  you want to do it the hard way, here's how.

Global $nU = "Name"
 
 
 
RunWait(@ComSpec & " /c echo " & $nU > 'C:\basicinfo.txt', "", @SW_HIDE)
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@BrewManNH - I tried the first code snippet that you posted - FileWrite('C:basicinfo.txt', $nu) - and it appears that it will work better for me as you stated it was the easier way.  So I will be using that instead of the first way I was trying. Being that I am new to this I don't quite have the ability right now to determine what is or is not an efficient way of coding. ;)  Anyway, I also tried using the second line of code you had said was the same as your first submission and would work but was the harder way to go about it.  Well, just so you are aware, I could not get it to work with the original code that I was trying to use.  Here is what I had been using with all of my combos and yours at the end.  I did abandon all of this for the much simpler code snippet you originally gave me but I was bent on trying to get my stuff working. :)

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.3
; Language:       English
; Platform:       Windows Vista & 7
; Author:         Me
;
; Script Function:
; Testing only
; ----------------------------------------------------------------------------

Global $nU = "Name"

;RunWait(@ComSpec & " /c " & 'echo "$nU" > C:basicinfo.txt', "", @SW_HIDE) ;creates C:basicinfo with "$nU" in the file.
;RunWait(@ComSpec & " /c echo " & '$nU > C:basicinfo.txt', "", @SW_HIDE)  ;creates C:basicinfo with "$nU" in the file.
;RunWait(@ComSpec & " /c echo " & '"$nU" > C:basicinfo.txt', "", @SW_HIDE)  ;creates C:basicinfo with "$nU" in the file.
;RunWait(@ComSpec & " /c echo " & "$nU > C:basicinfo.txt", "", @SW_HIDE) ;creates C:basicinfo with "$nU" in the file.
RunWait(@ComSpec & " /c echo " & $nU > 'C:basicinfo.txt', "", @SW_HIDE) ;this was the suggested one but does nothing at all.

But again, thank you very much for all of the information that you provided to me, as I can now play with this code along with other pieces of code to see how this all fits together. I am sure it may be sloppy at first but hopefully over time I will get to the point where I myself will be able recognize what works maybe both ways but is more efficient only one of them.  Thank you again.

Link to comment
Share on other sites

This will  work, it wasn't working before because of the single quotes around the file name, at least for me. I was getting a path not found error in the command window.

RunWait(@ComSpec & " /c echo " & $nU & ' >"C:\basicinfo.txt"', "", @SW_HIDE)

This won't work on Vista+ unless the script is run as an administrator because the root of the C drive is protected.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...