Jump to content
Sign in to follow this  
WhyTea

Run() problem when path has spaces

Recommended Posts

WhyTea

The following command runs find from a cmd shell:

"c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143

But it fails when I run it with Run(). The "c:\my editor\editor.exe" part is OK. The problem is with the file name part, which has space in the path. What is the correct way of using the Run() function in this case? (The same call works fine when there are no spaces in the path)

/Why Tea

Share this post


Link to post
Share on other sites
Valuater

I use FileGetShortName() and that has always worked for me

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
enaiman

Any white space (not included within quotes) will lead to errors most of the time:

- If you try to run c:\my editor\editor.exe in a cmd shell: you will get an error because the part after the white space (editor\editor.exe ) is believed to be an argument for c:\my command. If you put everything between quotes ("c:\my editor\editor.exe") it will run just fine.

The same thing is true with Run() command:

Run("c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143)

will give an error, while:

Run('""c:\my editor\editor.exe"" -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143')

would be fine.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
bo8ster

Like what enaiman says - I use this - _RunDos('copy /Y p:\Tools\devcon.exe "c:\Documents and Settings\All Users\Desktop\Tools"')

Also do this

Local $toolsPath = '"c:\Documents and Settings\All Users\Desktop\Tools\"'
Local $progPath = '"C:\Program Files\CustomFolder\"'

_RunDOS('mkdir ' & $progPath & ' ')
_RunDos('copy /Y /S' & $sourcePath & $progPath)

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
WhyTea

Any white space (not included within quotes) will lead to errors most of the time:

- If you try to run c:\my editor\editor.exe in a cmd shell: you will get an error because the part after the white space (editor\editor.exe ) is believed to be an argument for c:\my command. If you put everything between quotes ("c:\my editor\editor.exe") it will run just fine.

The same thing is true with Run() command:

Run("c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143)

will give an error, while:

Run('""c:\my editor\editor.exe"" -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143')

would be fine.

I tried this and it didn't work:

Run(@ComSpec & " /c " & '""c:\my editor\editor.exe"" -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143')

Share this post


Link to post
Share on other sites
omikron48

Run("c:\""my editor""\editor.exe -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143")

Don't use quotes on the program you want to run.

Edited by omikron48

Share this post


Link to post
Share on other sites
TurionAltec

There @comspec goes randomly sneaking in where it doesn't belong again.

Check strings section of "Language Reference - Datatypes" page in the help.

If you want to use double quotes in a string, do one of two things

Double up on the quotes("") or simply use single quotes for the AutoIT command. Code provided above has both. Try:

Run('"c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143')

And you can try a logic check that it's the correct command by using a message box:

Msgbox(0,"Title",'"c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143')
Edited by TurionAltec

Share this post


Link to post
Share on other sites
GEOSoft

Run("c:\""my editor""\editor.exe -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143")

Don't use quotes on the program you want to run.

That won't work either, you didn't concatenate the string.

Try this

ShellExecute(FileGetShortname("c:\my editor\editor.exe"), '-1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143')

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Mison

This topic might help:

http://www.autoitscript.com/forum/index.php?showtopic=103428&pid=732816&st=0&#entry732816


Hi ;)

Share this post


Link to post
Share on other sites
omikron48

@Geosoft: Why would I need to concatenate a single string? Two double quotes ("") in between two other double quotes is interpreted as a single double quote when the string is printed. It's the escape character to use double quotes.

'"text"' = "text"

"""text""" = "text"

"'text'" = 'text'

'''text''' = 'text'

Edited by omikron48

Share this post


Link to post
Share on other sites
TurionAltec

Try testing it:

ConsoleWrite("c:\""my editor""\editor.exe -1 ""C:\XXX\YY ZZ\AA_CBBB\my_src.cpp"" -n143"&@CR);omikron48
ConsoleWrite('"c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143'&@CR);Turionaltec

Result:

c:\"my editor"\editor.exe -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143
"c:\my editor\editor.exe" -1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143

The whole path must be enclosed in quotes.

For example this fails:

Run('C:\Program Files\"Microsoft Office"\OFFICE11\EXCEL.EXE')

Surrounding the whole string in single quotes, rather than using double double quotes avoids headaches.

Edited by TurionAltec

Share this post


Link to post
Share on other sites
omikron48

Yes, I know. But it's what I'm accustomed to, hence what I always use. I'm used to thinking single quotes define char(s) and double quote defines strings.

But if my memory serves me correct, you can just use double quotes on the subfolders of the path and the whole thing will be interpreted correctly by the command prompt, like:

C:\"Program Files"\somefolder\foo.exe

Edited by omikron48

Share this post


Link to post
Share on other sites
Mison

C:\"Program Files"\somefolder\foo.exe

Is this really works?? If it does, then I have learnt something new today


Hi ;)

Share this post


Link to post
Share on other sites
failedtocompile

@ WhyTea

Not sure if this will assist or not

$editorloc = 'c:\my editor\editor.exe'
$my_src = 'C:\XXX\YY ZZ\AA_CBBB\my_src.cpp'

Run(@comspec & ' /c ' & $editorloc & ' ' & '-1' & ' ' & $my_src & ' ' & '-n143', @SystemDir, @SW_SHOW)

or if you where to do it with just run:

$editorloc = 'c:\my editor\editor.exe'
$my_src = 'C:\XXX\YY ZZ\AA_CBBB\my_src.cpp'

run('"'& $editorloc & '" -1 "' & $my_src & '"-n143"')

Let me know how you go

ftc

Edited by failedtocompile

Share this post


Link to post
Share on other sites
WhyTea

That won't work either, you didn't concatenate the string.

Try this

ShellExecute(FileGetShortname("c:\my editor\editor.exe"), '-1 "C:\XXX\YY ZZ\AA_CBBB\my_src.cpp" -n143')

I tried but it didn't work. The editor ran but it didn't get the file name. Instead it loaded a new file called "'" (single quote).

/Why Tea

Share this post


Link to post
Share on other sites
TurionAltec

Yes, I know. But it's what I'm accustomed to, hence what I always use. I'm used to thinking single quotes define char(s) and double quote defines strings.

But if my memory serves me correct, you can just use double quotes on the subfolders of the path and the whole thing will be interpreted correctly by the command prompt, like:

C:\"Program Files"\somefolder\foo.exe

Commandprompt maybe, but not Autoit:

Consolewrite(Run('C:\Program Files\"Microsoft Office"\OFFICE11\EXCEL.EXE')&@CR)
ConsoleWrite(Run('"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"')&@CR)

Result:

0
884

For consistency it's best to use quotes around the entire path.

Share this post


Link to post
Share on other sites
herewasplato

I never knew that...

C:\"Program Files\Microsoft Office"\OFFICE11\EXCEL.EXE

and

C:\"Program Files"\"Microsoft Office"\OFFICE11\EXCEL.EXE

are valid at a cmd prompt.

I tend to drag and drop the exe from the Windows (file) explorer into the cmd window and the XP OS puts the quotes if needed:

"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"

So I've learned something - now that info will just push other stuff out :-(

:-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
GEOSoft

I never knew that...

C:\"Program Files\Microsoft Office"\OFFICE11\EXCEL.EXE

and

C:\"Program Files"\"Microsoft Office"\OFFICE11\EXCEL.EXE

are valid at a cmd prompt.

I tend to drag and drop the exe from the Windows (file) explorer into the cmd window and the XP OS puts the quotes if needed:

"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"

So I've learned something - now that info will just push other stuff out :-(

:-)

Then this will probably come as a total shock. :)

$sEnv = EnvGet("Path")
MsgBox(0, "Path", $sEnv)
EnvSet("path", $sEnv & ";C:\Program Files\Microsoft Office\OFFICE11")
EnvUpdate()
MsgBox(0, "Path", EnvGet("Path"))
ShellExecute("excel.exe")

Or to simplify it

EnvSet("path", EnvGet("Path") & ";C:\Program Files\Microsoft Office\OFFICE11")
EnvUpdate()
ShellExecute("excel.exe")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
omikron48

Doesn't that just add the folder into the Path variable where Windows searches for stuff by default?

It's the same as sticking a batch file or exe into the WINDOWS folder and being able to run it directly from Start Menu->Run or in this case, ShellExecute.

Edited by omikron48

Share this post


Link to post
Share on other sites
herewasplato

Then this will probably come as a total shock. :) ...

...it did shock me, but probably not in the way that you think. It does not surprise me to see the lack of quotes there since that areahas no exes & parms to be delimited. Everything between thesemicolons can be considered part of a path.

My shock came from the realization of just how long it had been since I've typed "PATH" into an old fashion "DOS" window... It brought to mind a few hours that I spent watching contractors attempt to convert a computer from unrouted to routed network traffic. The solution just was not in the 3 ring binder that they kept flipping thru. I offered to help and they said no thanks. They totally hosed the computer since they did not notice that is was IBM's PC DOS 6x and the files that they copied to it were from MS DOS 6x. I had the pleasure of rebuilding the box - but back then, that only meant putting the right files back in place.

Since this conversion to routed traffic was being done one data closet at a time - we were disconnected from our file server for two weeks. So... sneakernet,

I converted that one box to routed traffic and my box

Three months later, we moved to a different building

I converted ~15 boxes back to unrouted traffic

One month later, the contractors converted the one data closet in that building

I converted them to routed traffic

Ahh, the wonderful world of a corporate cog.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
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
Sign in to follow this  

×