Jump to content

WARNING about Run command and Notepad++


Recommended Posts

Just a word to the wise folks about trying to invoke notepad++.exe using the Run command: it won't work!

For some reason the Run command does not like the 2 +'s at the end of the filename.

I have tried and proved this by creating a stub that does nothing else but try to kick it off and it fails with a 0 handle and an @error of 1 until I remove the 2 +'s and then it fires it up nicely. This is, of course, only of use to me as other users who have installed Notepad++ won't want to rename the exe file as this will break the upgrade path.

This is most annoying as I use the full path to notepad++ in an ini file to allow users to choose their favourite editor when using my app and it defaults to Notepad (as it is designed to do) because it cannot "find" notepad++ (which was how I came to investigate the problem in the first place).

This didn't used to happen in earlier versions, any ideas Jon? It might even be the notepad++'s exe file used to not have the 2 +'s in but I have no way of finding this out.

Link to comment
Share on other sites

Try this:

Run('"C:\Program Files (x86)\Notepad++\notepad++.exe"')

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

jmollerhead,

This executes either Notepad++ or Notepad based on a selection from an ini file...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>
#include <GuiComboBox.au3>

#AutoIt3Wrapper_Add_Constants=n

local $aEditors = IniReadSectionNames(@scriptdir & '\test.ini')

local $gui010 = guicreate('Ini Run Editor Test',200,150)
local $aSize  = WinGetClientSize($gui010)
local $lbl010 = guictrlcreatelabel('Choose Which Editor To Start',20,15,200,20)
local $inp010 = guictrlcreatecombo('',20,35,100,20)
local $btn010 = guictrlcreatebutton('',20,100,150,20)
guisetstate()

guictrlsetdata($inp010,_arraytostring($aEditors,'|',1))
_GUICtrlComboBox_SetCurSel($inp010,0)
guictrlsetdata($btn010,'Run ' & guictrlread($inp010))

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $inp010
            guictrlsetdata($btn010,'Run ' & guictrlread($inp010))
        case $btn010
            shellexecute(inireadsection(@scriptdir & '\test.ini',guictrlread($inp010))[1][1])
    EndSwitch
WEnd

Th ini file looks like this

[Notepad++]
ed=C:\Program Files (x86)\Notepad++\notepad++.exe
[Notepad]
ed=C:\Users\ADMIN010\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad

kylomas

edit: >Running:(3.3.12.0):C:Program Files (x86)AutoIt3autoit3.exe "C:UsersADMIN010Documentsaa.au3"

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Can't test at the moment, but did you always run Notepad++.exe after a read from the INI file?

If so, then perhaps the INI read is not returning the correct name?

Some characters don't read and write correctly with INI commands.

For instance, you can have a single quote for an INI entry, but if you have one at both the start and end of a value, then they both get stripped.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

@The Saint - in case you missed post #6 here's another...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>
#include <GuiComboBox.au3>

#AutoIt3Wrapper_Add_Constants=n

local $aEditors = IniReadSection(@scriptdir & '\test.ini',"editors")

local $gui010 = guicreate('Ini Run Editor Test',200,130)
local $lbl010 = guictrlcreatelabel('Choose Which Editor To Start',20,15,200,20)
local $inp010 = guictrlcreatecombo('',20,35,100,20)
local $btn010 = guictrlcreatebutton('',20,100,160,20)
guisetstate()

for $1 = 1 to ubound($aEditors) - 1
    guictrlsetdata($inp010,$aEditors[$1][0])
next

_GUICtrlComboBox_SetCurSel($inp010,0)
guictrlsetdata($btn010,'Run ' & guictrlread($inp010))

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $inp010
            guictrlsetdata($btn010,'Run ' & guictrlread($inp010))
        case $btn010
            shellexecute(iniread(@scriptdir & '\test.ini','editors',guictrlread($inp010),''))
    EndSwitch
WEnd

#cs

The ini file looks like this

[editors]
notepad++=C:\Program Files (x86)\Notepad++\notepad++.exe
notepad=C:\Users\ADMIN010\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad

#ce

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@kylomas - I did notice your post, but when I saw you had used Execute instead of Run, I didn't look at it in detail, for the OP wasn't requesting an alternative, just reporting what he thought was an error with Run.

Execute is indeed, often the better method.

Just looking again at your repeat, I scrolled far enough to see the INI entry stuff.

Thanks, I had missed that ... it was only an outside chance thought of mine anyway.

P.S. The size of my netbook screen, sometimes means I miss elements, if I don't scroll far enough.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

@The Saint - Apologies, I was a little short last night.  The point was to demonstrate to the OP that the "++" was not a problem, like...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>
#include <GuiComboBox.au3>

#AutoIt3Wrapper_Add_Constants=n

local $aEditors = IniReadSection(@scriptdir & '\test.ini',"editors")

local $gui010 = guicreate('Ini Run Editor Test',200,130)
local $lbl010 = guictrlcreatelabel('Choose Which Editor To Start',20,15,200,20)
local $inp010 = guictrlcreatecombo('',20,35,100,20)
local $btn010 = guictrlcreatebutton('',20,100,160,20)
guisetstate()

for $1 = 1 to ubound($aEditors) - 1
    guictrlsetdata($inp010,$aEditors[$1][0])
next

_GUICtrlComboBox_SetCurSel($inp010,0)
guictrlsetdata($btn010,'Run ' & guictrlread($inp010))

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $inp010
            guictrlsetdata($btn010,'Run ' & guictrlread($inp010))
        case $btn010
            run(iniread(@scriptdir & '\test.ini','editors',guictrlread($inp010),''))
    EndSwitch
WEnd

#cs

The ini file looks like this

[editors]
notepad++=C:\Program Files (x86)\Notepad++\notepad++.exe
notepad=c:\windows\notepad.exe

#ce

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

OK folks, I put the original post on from work so I was a bit surprised by the response (especially SadBunny's unjustified accusation) so here's some feedback....

I am actually reading from an ini file like so:

$Editor = IniRead("Textreme.ini", "Global Settings", "TextEditor", "Notepad.exe")

The ini file has this:

[Global Settings]
TextEditor="C:Program Files (x86)Notepad++notepad++.exe"
 
I began the debug exercise by using msgbox to echo back the contents of $Editor and it was fine.
 

This has worked fine until quite recently and I don't know why it has suddenly started acting up... foolishly I have left the RAM drive with the most recent version at work so I can't try it on my Win8 64 bit machine here but my work machine is Win7 64 bit.

The +'s are fine as I retyped them from the keyboard.

After the debugging within the main app echoed the path correctly, I decided on a 'pare down to the bone' test with a stub. The stub I used was something like:

Global $RunHandle

$RunHandle = Run("C:Program Files (x86)Notepad++notepad++.exe")

MsgBox(0, "Run Result", "Handle: " & $RunHandle & " Erc: " & @error)

In fact I just ran this on my Win8 machine and it invokes Notepad++ fine.... I will try some more stuff at work and come back to let you know. As I said it failed at work with a handle of 0 and an @error of 1 which was a surprise as it had worked perfectly up to now.

If anyone would be willing to try it out "in anger" for me then you can download Textreme from jollybean.uk... if it works fine for you (just use "Open Source File" to save having to create and run a process) then it must be something weird that has been done to my work machine. If that's the case then sorry for the false warning!

Regards and thanks for the replies,

Jim.

P.S. Just editing this to add an afterthought... you say ShellExecute is 'better' than Run... could you say why? and when, in that case, you would ever use Run rather than ShellExecute?

Edited by jimollerhead
Link to comment
Share on other sites

I presume this is the right one - http://www.jollybean.co.uk/page12.html

Nothing is readily apparent, about your issue, and as you haven't provided a significant enough portion of code, we cannot really tell what the issue might be.

Others have stated it works fine for them, so it is most likely some little error in your code somewhere or a path.

IMPORTANT - By the way, it is not AutoIT .... it is AutoIt .... not Eye Tee at all ... and auto as in automating it.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

OK folks, I put the original post on from work so I was a bit surprised by the response (especially SadBunny's unjustified accusation) so here's some feedback....

 

Oh come on man, I was just kidding. I offered my actual serious suggestion in the same sentence, you know, like unicode +'es, which could well have been the problem (could still be if you have weird keyboard/multinational setups).

Aaaanyway...

If anyone would be willing to try it out "in anger" for me then you can download Textreme from jollybean.uk... if it works fine for you (just use "Open Source File" to save having to create and run a process) then it must be something weird that has been done to my work machine. If that's the case then sorry for the false warning!

 

Yeah so to try and show my good will, which I already showed IMHO by giving you two useful pieces of feedback -you're welcome, btw-, I decided to trust you and run the exe, which I normally would not do with so little information. I downloaded the zip, extracted the exe and the ini into the temp file and ran it. Opened a text file and *plop* notepad++ appeared without any problems.

So, again... Works for me! :D

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

jimollerhead,

P.S. Just editing this to add an afterthought... you say ShellExecute is 'better' than Run... could you say why? and when, in that case, you would ever use Run rather than ShellExecute?

 

In this case there is little or no difference. 
It is a habit with me because I often use ShellExecute for opening files, like

ShellExecute('my.file.txt')

which will find the program associated with .txt and run it with the default verb (in most cases "Open").

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

OK thanks very much for trying that out SadBunny....and thanks for the info kylomas.

@TheSaint, yes I knew this, in fact it was pointed out to me by Jon when I asked him to do a quick sanity check on my text about AutoIt on my website as I had used 2 caps on that as well!

Thanks to all in general for the replies, as I said earlier it works fine on my own Lenovo at home but this works machine still doesn't like it...I'm not that fussed though now I know it works for everyone else.

Link to comment
Share on other sites

P.S. Just editing this to add an afterthought... you say ShellExecute is 'better' than Run... could you say why? and when, in that case, you would ever use Run rather than ShellExecute?

I really cannot say which is better, other than to use a URL as an example.

You could choose to use a specific browser, which might upset the user or you could use the system default.

System default, by using ShellExecute would be much smarter, and the right thing to do.

It also means, that you don't need to know what program on the user's PC is required to open a URL or a text file or some other non-executable.

If however, you wanted a text file to open in WordPad (or Notepad++) instead of Notepad, for some reason, then Run is your better bet ... though you could also use ShellExecute for WordPad (etc) and provide the text file as a parameter. ShellExecute can be slower though than Run. If you had several EXE files in you script directory, then Run is probably easier.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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

×
×
  • Create New...