EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     macro to execute external tool with prompts
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
kenny
Posted on: 5/11/2009 7:42 pm
Just popping in
Joined: 5/11/2009
From:
Posts: 7
macro to execute external tool with prompts
I can't see how do do this, but is it possible to write a macro to execute an external tool with prompts for the parameters prior to execution?

Specifically, I want to execute the osql command line tool passing the current file path/name [no problem here]. But I also want to prompt for the server and database parameters.

Any thoughts?
Yutaka
Posted on: 5/12/2009 8:43 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2399
Re: macro to execute external tool with prompts
Quote:

kenny wrote:
I can't see how do do this, but is it possible to write a macro to execute an external tool with prompts for the parameters prior to execution?

Specifically, I want to execute the osql command line tool passing the current file path/name [no problem here]. But I also want to prompt for the server and database parameters.

Any thoughts?


For this purpose, you will need to write a macro. External Tools currently cannot include a user interface to input parameters.


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

kenny
Posted on: 5/12/2009 2:52 pm
Just popping in
Joined: 5/11/2009
From:
Posts: 7
Re: macro to execute external tool with prompts
Quote:
For this purpose, you will need to write a macro. External Tools currently cannot include a user interface to input parameters.


Thanks for the reply, but what I'm asking is how to write this macro. I can see hpow to execute an external tool from a macro, but I can't see how to pass parameters to it in a macro.
Yutaka
Posted on: 5/12/2009 5:44 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2399
Re: macro to execute external tool with prompts
Quote:

kenny wrote:
Quote:
For this purpose, you will need to write a macro. External Tools currently cannot include a user interface to input parameters.


Thanks for the reply, but what I'm asking is how to write this macro. I can see hpow to execute an external tool from a macro, but I can't see how to pass parameters to it in a macro.


You would write something like this:

WshShell = new ActiveXObject( "WScript.Shell" );
sCmdline = prompt( "Command line: ", "" )
WshShell.Run( "app.exe", sCmdline );


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

kenny
Posted on: 5/12/2009 6:30 pm
Just popping in
Joined: 5/11/2009
From:
Posts: 7
Re: macro to execute external tool with prompts
OK, I can see how I could get this working, but it's not calling one of the configured external tools [i.e. tools menu -> external tools].

This is still OK, but can I capture the output of WshShell.Run( "app.exe", sCmdline ); ?
Yutaka
Posted on: 5/12/2009 8:20 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2399
Re: macro to execute external tool with prompts
Quote:

kenny wrote:
OK, I can see how I could get this working, but it's not calling one of the configured external tools [i.e. tools menu -> external tools].

This is still OK, but can I capture the output of WshShell.Run( "app.exe", sCmdline ); ?


How about this?


sCmdline = prompt( "Command line: ", "" )
var wsh = new ActiveXObject("WScript.Shell");
wExec = wsh.Exec("app.exe " + sCmdline);

OutputBar.Visible = true;
OutputBar.SetFocus();
OutputBar.writeln("--------");
OutputBar.write(wExec.StdOut.ReadAll());
OutputBar.write(wExec.StdErr.ReadAll());


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

kenny
Posted on: 5/12/2009 10:15 pm
Just popping in
Joined: 5/11/2009
From:
Posts: 7
Re: macro to execute external tool with prompts
I'm getting somewhere, but not quite there yet.
Using vb rather than jscript [code below]
It doesn't seem to like the ReadAll lines.
I can't find any reference to this in the help file. Maybe I should be looking at some vbscript references instead.

Any thoughts?


sServer = prompt("Enter Server", "MyServer")
sDatabase = prompt("Enter Database", "MyDB")
sFileName = "MyFile.sql"
sCmdline = "-w""2000"" -S""" + sServer + """ -E -d""" + sDatabase + """ -n -t28800 -I -i""" + sFileName + """"

set wsh = CreateObject("WScript.Shell")
wExec = wsh.Run("osql.exe " + sCmdline)

OutputBar.Visible = true
OutputBar.SetFocus()
OutputBar.writeln("--------")
OutputBar.write(wExec.StdOut.ReadAll())
OutputBar.write(wExec.StdErr.ReadAll())
kenny
Posted on: 5/12/2009 10:18 pm
Just popping in
Joined: 5/11/2009
From:
Posts: 7
Re: macro to execute external tool with prompts
OK, I have it now. Many thanks for your help

Missed a set statement.
code should have been
sServer = prompt("Enter Server", "MyServer")
sDatabase = prompt("Enter Database", "MyDB")
sFileName = "MyFile.txt"
sCmdline = "-w""2000"" -S""" + sServer + """ -E -d""" + sDatabase + """ -n -t28800 -I -i""" + sFileName + """"

set wsh = CreateObject("WScript.Shell")
set wExec = wsh.exec("osql.exe " + sCmdline)

OutputBar.Visible = true
OutputBar.SetFocus()
OutputBar.writeln("--------")
OutputBar.write(wExec.StdOut.ReadAll())
OutputBar.write(wExec.StdErr.ReadAll())

Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文