Jump to content

Recommended Posts

Posted

So, what I'm trying to do is open a program (exe) with command-line arguments, which...if I'm understanding the helpfile...means I need to use  ShellExecute instead of Run?

The command line I need to use is...

"C:Program FilesMyPhoneExplorerMyPhoneExplorer.exe" action=dial number=012345678

But with a simple text-input box to replace the number, so it asks for user (that's me) input & fills in the line with my result.

How hard is something like this?

  • Moderators
Posted

TheLandYacht,

 

  Quote

How hard is something like this?

Very easy - give it a try. :)

I would suggest using InputBox to get the user input and then concatenating the returned data to the basic string. Take care with spaces and quotes though - that is where most such strings fail. Use ConsoleWrite or MsgBox to check that the result is correct before trying to ShellExecute it. ;)

Come back if you run into problems - but try and produce something yourself first. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

OK.  First attempt met with some success, but ultimate failure.  Here's what I got.  I copied straight from the InputBox & ConsoleWrite examples for most of this (with some modification)

The first line that's commented out at the top, I confirmed working just by dialing my own number...then commented it out.

The InputBox looks like it's working, I just had it spit out the result to the ConsoleWrite (which I can read at the bottom of SciTe).

Then comes the part where I'm having a bit of trouble.  If ALL I include is the result of the InputBox, it spits it out just as expected.  But if I try to add the rest in front of it, it errors out.  Not just spitting out the wrong results, but errors out before I see an InputBox pop up.

What am I doing wrong here?

;~ShellExecute ( "C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe", "action=dial number=51261234567" )

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Places the input box in the center of the screen displaying the characters as they
    ; are typed.
    Local $sAnswer = InputBox("Phone#", "Phone Number?", "512", "", _
             - 1, -1, 512, 354)

    ; Display the result.
    ConsoleWrite ( $sAnswer & @CRLF) ;-THIS ONE WORKS
    ;-ConsoleWrite ( "C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe", "action=dial number= $sAnswer & @CRLF)
    ;-ConsoleWrite ( "C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe", "action=dial number=" $sAnswer & @CRLF)

EndFunc
Edited by TheLandYacht
  • Moderators
Posted

TheLandYacht,

You need another concatenation operator to join the input and the string: ;)

ConsoleWrite ( "C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe", "action=dial number=" & $sAnswer & @CRLF)
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

OK.  I just copied your line verbatim into my script (after commenting out the one that DOES work)...and got...

 

error: ConsoleWrite() [built-in] called with wrong number of args.

  • Moderators
Posted

TheLandYacht,

I did tell you that you needed to be careful with quotes! :D

ConsoleWrite("C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe, action=dial number=" & $sAnswer & @CRLF)
Now it will display as a single string.

If that looks right, then when you actually use the value with ShellExecute you will need:

ShellExecute("C:\Program Files (x86)\MyPhoneExplorer\MyPhoneExplorer.exe", "action=dial number=" & $sAnswer)
to split it into the 2 required parameters.

Command lines are always fun. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

That worked perfectly.  And yes, you did mention watching spacing.  I've just seen that the majority of examples I've viewed include a space between the command and the (, as well as another space inside the ( in most cases...so I thought that was the norm.

There was another way to do it (that will probably end up being easier in the long run), but I figured I'd tackle this method too...just so I could say I had understood how/why this works.

The other method includes sending a ControlSend to the program, followed by the results of the above InputBox.

From a programmer/coder perspective, is there one way or the other that's considered more "elegant"?

  • Moderators
Posted

TheLandYacht,

If it works - it works. Personally I would go for the ShellExecute method, but that is purely my preference. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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