run a DOS command without the cmd window opening

rab tab rabtab70 at gmail.com
Sun Jan 28 15:32:06 EST 2018


Thanks very much for this example, Micheal. It has started me down the path of exploring Shell32.dll.  However, I’ve discovered that there is virtually no reference for, or documentation of, Shell32.dll. 

I have looked long and hard in search engines for a basic reference to how it works, and I’m coming up empty handed. Lots of postings about how “Shell32.dll is a part of Windows,” and "don’t delete it" but virtually nothing that would count as a reference or ‘how to.’ Any pointers to reference docs would be very welcome.

My case is a bit different than the example Michael gave. In my case, I’m issuing a command to psql and I need to send the password first.

Here’s the command I’ve been using in the CMD shell to restore the database from backup. It sends stderr to a file:

PGPASSWORD=[myPassword]
"C:\Program Files (x86)\PostgreSQL\9.5\bin\psql.exe” -U theUserName -p thePort -f "C:\ProgramData\[thePathToTheFileToRestore]\myFile.backup" postgres  2> "C:\Users\myDir\restorecluster_stderr.txt”

First I register the dll :

Calculate ShellCmd as 'ShellExecuteW'
Register DLL ('Shell32.dll',ShellCmd,'JJCCCCJ') Returns errorCode

that returns no error. Then I attempt to execute the command with:

Call DLL ('Shell32.dll',ShellCmd,0,DosExe,DosCmdArgs,'','#NULL#',1) Returns errorCode

where DosExe=

PGPASSWORD=[myPassword]
"C:\Program Files (x86)\PostgreSQL\9.5\bin\psql.exe”

and DosCmdArgs=

-U theUserName -p thePort -f "C:\ProgramData\[thePathToTheFileToRestore]\myFile.backup" postgres  2> "C:\Users\myDir\restorecluster_stderr.txt”

this returns errorCode 2 "File was not found”

So, there may be a problem with including the password string as part of the DosExe. I tried sending the password string as a separate Call DLL.

Calculate DosSetPW as con('SET PGPASSWORD=', myPassword)
Call DLL ('Shell32.dll',ShellCmd,0,DosSetPW,'','','#NULL#',1) Returns errorCode

but this returns errorCode 31 'No association found for the specified file’

If anyone can spot where I’m going wrong (and I really don’t know much about Shell32) I’d really appreciate some guidance.

Thanks much, everyone.

Rob Alexander


"Straight ahead and strive for tone." -- Frank Marocco

> On 20180117, at 14:49, Michael Mantkowski <michaelj at clientrax.com> wrote:
> 
> Try something like this.
> 
> Register DLL ("Shell32.dll",con('ShellExecute',pick(inU,'A','W')),"JJCCCCJ") Returns lvReturn     ;; Allow for ShellExecute calls
> Calculate lvProgram as 'C:\Program.exe'
> Calculate lvCommand as '\a \b'
> Call DLL ("Shell32.dll",con('ShellExecute',pick(inU,'A','W')),0,"#NULL#",lvProgram,lvCommand,"#NULL#",1) Returns lvErrorCode
> 
> 
> *********************************************************************
> Michael Mantkowski
> ClienTrax Software
> 1-614-875-2245
> *********************************************************************
> 
> 
> -----Original Message-----
> From: omnisdev-en [mailto:omnisdev-en-bounces at lists.omnis-dev.com] On Behalf Of rab tab
> Sent: Wednesday, January 17, 2018 2:45 PM
> To: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
> Subject: run a DOS command without the cmd window opening
> 
> Hi,
> 
> In the application I’m working on we occasionally interact with postgres via the command line (pg_dumpall, psql…) on both PCs and Macs, so either the BASH shell or DOS cmd.
> 
> No issue on Unix, but in Windows the blank black cmd window opens up and sits there until the operation is finished. Sometimes, a confused user will close it, and it messes things up. 
> 
> I want to be able to run the DOS command ‘headless,’ ie, without the cmd window opening.
> 
> I’ve tried using ‘start’ to minimize the window...
>> start /MIN ‘’ … [the rest of my command, which sends stderr output to a file]
> which works quite nicely except that then the command does not write output to stderr, which I need.
> 
> Played with the /B option as well, but no joy.
> 
> Does anyone have a way to accomplish when I need?
> 
> Thanks a lot. :-)
> 
> Rob Alexander
> 
> "Straight ahead and strive for tone." -- Frank Marocco
> 
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com
> 
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com




More information about the omnisdev-en mailing list