Jump to content

"Run" broken by brackets in filename


Guest Guest_oYx
 Share

Recommended Posts

Guest Guest_oYx

here is a simplified example of how it doesn't run:

Run (@ComSpec & " /c C:\(test).txt")

here is the actual line from my script, which allows me to run any file that windows recognises:

Run (@ComSpec & " /c " & """" & $targetpath & $file & """", "", @SW_HIDE)

any idea how to resolve that? :D

Link to comment
Share on other sites

here is the actual line from my script, which allows me to run any file that windows recognises

Not quite. You can't run anything except Exe and Com files without using the application required to run them. For example, if you had the full path of a text file in $file, you could open them with notepad by using:

Run(@ComSpec & " /c notepad.exe " & '"' & $file & '"', "", @SW_HIDE)

If your filename contains the "&" character, it shouldn't matter.

Typo corrected

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

This seems to work:

Run(@ComSpec & ' /k ""C:\(test).txt""')

as does this (odd looking) bit:

Run(@ComSpec & ' /k C:\"(test).txt"')

Perhaps double quotes will also fix the ampersand issue, too.

The last paragraph of a cmd /? says this:

The special characters that require quotes are:

  <space>

  &()[]{}^=;!'+,`~

Possible reason this occurs: The double quotes are necessary because of the way the command line works. Let's break down what each program is getting:

Using this string:

@ComSpec & ' /k "C:\(test).txt"'

Console (@ComSpec) gets this string passed to it:

/k C:\(test).txt

Notice the lack of quotes around the file name. That's because they were stripped when passed. Now, when the command interpreter tries to run it, it errors because file names with () need to be in quotes.

Now take the string:

@ComSpec & ' /k ""C:\(test).txt""'

The command interpreter gets:

/k "C:\(test).txt"

So now when it tries to run the file name to open it, it has a properly quoted file name to use.

This may seem very confusing, but it is normal. I can reproduce all the success and failure cases with or without AutoIt.

Link to comment
Share on other sites

Not quite.  You can't run anything except Exe and Com files without using the application required to run them.

not true. :D

i have used it to run any file that i can run by double-clicking on in windows explorer. for example: mp3, avi, mid, jpg, wav, etc.

as long as it's already associated with the program that runs the file in windows, that line will run them.

Link to comment
Share on other sites

Valik,

i'm going to accuse you of being nice now. :D

thanks for your time in replying. i'll try your method out now.

Link to comment
Share on other sites

Run (@ComSpec & " /c " & '""' & $file & '""', "", @SW_HIDE)

that runs every file now - even with special characters in the filename.

thanks for the push in the right direction! :D

Edited by oYx
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...