Jump to content

Shell command language bug? - (Moved)


Recommended Posts

For this experiment first we're going to make 2 folders in C:\ or whichever drive. New folder and Newfolder. In both were putting File.txt which can be blank.

Now we're going to make a quick script to open File in both folders. Let's look at the documentation. https://ss64.com/nt/start.html

Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""

Alright we will leave the empty quotes. And it looks from this that the quotes are there to account for spaces.

Open a file with a particular program:
START "" "C:\Program Files\Microsoft Office\Winword.exe" "D:\Docs\demo.txt"

And we can disable the particular program part altogether.

Non-executable files can be invoked through their file association just by typing the name of the file as a command. (e.g. WORD.DOC would launch the application associated with the .DOC file extension).

So this should work.

Global Const $sFilePath = "C:\New folder\File.txt"

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

Perfect. All that's left is that the surrounding quotes are part of Microsoft's plan. So if we take off the surrounding quotes it won't work on the other folder, regardless of intuition that it doesn't need the quotes in that case. The "" is for the title being the same, leave nothing for your default program, but your default program won't know what to do without the surrounding quotes.

Global Const $sFilePath = "C:\Newfolder\File.txt"

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

And it doesn't.

But surely, that means completely aping the code will not work

Global Const $sFilePath = "C:\Newfolder\File.txt"

Run(@ComSpec & " /c start " & $sFilePath, "", @SW_HIDE)

NOPE! WORKS. You can save your characters, have a working program and think absurdly that this will translate into directories with spaces. How naive the fool!

Global Const $sFilePath = "C:\New folder\File.txt"

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

 

Edited by moosjuice
Link to comment
Share on other sites

  • Developers
1 hour ago, moosjuice said:

And it doesn't.

You are missing a space after ""

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

... and why the extra concatenation (which I see a lot of people do)?  Isn't this easier?

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

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Alright, now that I reflect those quotes were misonstrued to what even I was talking about in the last sentence, at a glance the quotes for default title look like the quotes next to @SW_HIDE side of the expression look like it's adjacent when actually it has to do with Autoit (working directory), on top of it that it is genreally neat to have quotes up against the side of anything else. This is a rare case where I would actually want to not concatenate because even though it's a separate parameter, it looks like all the quotes everywhere. But while now it's not anymore the dramatic crescendo I wanted, I still think it's a bug to support spaceless and have something not be able to be intuitively changed.

Link to comment
Share on other sites

  • Developers

@moosjuice, 

Ever considered writing books? (referring to your elaborate writing style, which isn't easy for none english natives like me) ;) 
The easiest way of checking is to simply write the total result with a consolewrite() to be able to check whether it is properly formed.

EDIT:

4 minutes ago, moosjuice said:

I still think it's a bug to support spaceless and have something not be able to be intuitively changed.

No idea what that means so please so a simple example of what in your mind is wrong and how it should be.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Talk to Microsoft, it's their issue, they're the ones that require quotes around file paths/names with spaces in them.

The best way to check if your quotes are in the right places is to use ConsoleWrite on the command line for Run before using it in Run. ConsoleWrite will show you exactly how it will look to ComSpec when you Run it.

Second hint, NEVER EVER use /c or @SW_HIDE until your command runs successfully, only use those in production code or you're never going to see where you screwed up.

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

@Jos

Thanks. I've always been the wordsmith, it helps to keep notes as you hear expressions. Still no one believes it's a bug, or absurd that it doesn't translate from spaceless to spaces. To put it another way as a programming language you can't have arbitrary rules because they are superfluous. Users expect the language to be compact, when there is a precedent set because of that assumption they will try to use the rest of the program as though that's the only way it will be recognized.

@BrewManNH

That's good advice. I've been starting to use ConsoleWrite but for GUIs it can also be satisfying to use the message boxes. I've been lucky that all I've done is low level file operations while being blind and just AB testing but to be safe hobbyists should check out https://ss64.com/nt/cmd.html and take advantage of the full parameters you can set to CMD as you safely view it.

Link to comment
Share on other sites

  • Developers
1 minute ago, moosjuice said:

Still no one believes it's a bug, or absurd that it doesn't translate from spaceless to spaces.

I don't know yet as I haven't seen any example that clearly (for me) proves your point and isn't covered by a word-wall. 
So do me a simple favor and show a basic runnable example that in your mind should work and doesn't. :) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

4 hours ago, moosjuice said:

that means completely aping the code will not work

Global Const $sFilePath = "C:\Newfolder\File.txt"

Run(@ComSpec & " /c start " & $sFilePath, "", @SW_HIDE)

NOPE! WORKS. You can save your characters, have a working program and think absurdly that this will translate into directories with spaces. How naive the fool!

Global Const $sFilePath = "C:\New folder\File.txt"

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

^Doesn't work

 

Link to comment
Share on other sites

5 minutes ago, moosjuice said:

^Doesn't work

This is what I get with that exact code above, except I used a consoleWrite, like I told you to do, instead.

Global Const $sFilePath = "C:\New folder\File.txt"
;~ Run(@ComSpec & " /c start " & '"' & $sFilePath & '"', "", @SW_HIDE)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c start " & ''"'' & $sFilePath & ''"'' = ' & @ComSpec & " /c start " & '"' & $sFilePath & '"' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

This is the output from that.

Quote

C:\WINDOWS\system32\cmd.exe /c start "C:\New folder\File.txt"

Properly formatted, and with quotes in the right place, so I don't see why it won't work.

 

Instead of crying bug, try using some error checking before.

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

It is not a bug of the autoit run function.  I would call it a feature of the start command.  You can go directly into a cmd.exe console and execute the same commands you were testing and it will react exactly in the same manner.  

Link to comment
Share on other sites

  • Developers

As already mentioned by the 2 previous posts:

You are shelling this command: 

C:\WINDOWS\system32\cmd.exe /c start "C:\New folder\File.txt"

Which indeed fails from the CMD.exe prompt.
... but why not simply use ShellExecute() as that is made for this?:

ShellExecute($sFilePath)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

16 minutes ago, BrewManNH said:

This is what I get with that exact code above, except I used a consoleWrite, like I told you to do, instead.

Global Const $sFilePath = "C:\New folder\File.txt"
;~ Run(@ComSpec & " /c start " & '"' & $sFilePath & '"', "", @SW_HIDE)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c start " & ''"'' & $sFilePath & ''"'' = ' & @ComSpec & " /c start " & '"' & $sFilePath & '"' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

This is the output from that.

Properly formatted, and with quotes in the right place, so I don't see why it won't work.

 

Instead of crying bug, try using some error checking before.

You are totally ahead of your skiis. Try reading my post before claiming to know what is the proper format of the Start function.. and then run it yourself from the Run prompt.

13 minutes ago, Jos said:

 

Which indeed fails from the CMD.exe prompt.

We have confirmation. Thanks for the function but my work here is done.

Link to comment
Share on other sites

38 minutes ago, moosjuice said:

Try reading my post before claiming to know what is the proper format of the Start function

Try using error checking before thinking you know more than others do. I was only looking at the format of the quotes and the string, I couldn't care less what the format of the Start command is, it's immaterial. I assumed that you were smart enough to have figured out how to properly format the command line for what you wanted it to do. I don't play in the command console much these days unless absolutely necessary.

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

  • Developers

Mmm ... Guess I've seen enough here as there are too many words countering words and not enough substance.

Enjoy. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos

You are not innocent in all this. You moved my thread from the PowerShell to Autoit, leading @BrewManNH to think I was complaining about autoit. I was going to complain about it earlier but that was on the assumption that @BrewManNH was only talking about the piece of code that I corrected and not the very basic, easy to interpret what was going to the command prompt pieces of code at the bottom, but it escalated a bit quickly. I also slightly disagree that even if it was in Autoit, or if there was a debug tool for CommandLine, I would consider everytime someone had to use that for something as basic as what's on the bottom (because 2 syntaxes exist to do the same thing), that it is a damage control mechanic for a bug.

Link to comment
Share on other sites

  • Developers

wtf is wrong with you? 
You posted an AutoIt3 script question in the wrong forum so it got moved....  deal with it and stop the arguing for a change.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
  • Moderators

As has been seen many times, and I am willing to bet experienced many times yourself throughout your life - admit it to anyone else or not - even if your post had merit, the message was lost amid your unfounded arrogance (as it was pointed out you were simply doing things incorrectly) and your caustic demeanor toward others.

We are all for folks wanting to add to and improve the language but the comments made to others who have proven experience with the language and belittling their responses are not going to win you any friends here.

Edited by JLogan3o13

"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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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