WshShell.Run question 
Author Message
 WshShell.Run question

Hi,

I have a script that is part of an automated mail archiving system. The
script builds a command line based on various parameters, and then
passes the command line to the run method of WshShell. (The program it
calls is actually a BAT file, not and EXE file).

When I run the script, it builds the command line perfectly, but when
the string is submitted to WshShell.Run it just pops up a black screen
(very quick) and fails with a return code of "1". (I'm using
"bWaitOnReturn").

It seems I can't "pause" this black screen (CMD session) to see what
went wrong. If I send the command line string to a text file using FSO,
then copy and paste the command line into a Windows NT CMD session it
works perfectly!

The only non-standard thing about this command line is that it encloses
one of it's parameters in double quotes. Maybe this could be messing
things up? The command line does not use long file names or spaces in
file names. I tried wrapping the whole thing in double quotes and this
didn't seem to work either. The command line looks a bit like this:

c:\scripts>c:\perl\bin\mhonarc.bat f:\mailarc\in -add -rcfile
f:\mailarc\zak.rc -mhpattern "^*.CNM" -outdir f:\mailarc\out

NOTE; the above line may have wrapped! It's actually all on one line.

The regex has to go in double quotes (I think) to work on NT.

--
Gerry Hickman (London UK)



Sun, 18 May 2003 03:00:00 GMT  
 WshShell.Run question
Please publish your code so I could debug it.


Sun, 18 May 2003 03:00:00 GMT  
 WshShell.Run question
Hi Reino,

Quote:
> Please publish your code so I could debug it.

Unfortunately, the code is on a remote server. I can't get it 'till next
week. The command line is exactly as stated, and is passed as a string
to WshShell.Run() in JScript.

--
Gerry Hickman (London UK)



Sun, 18 May 2003 03:00:00 GMT  
 WshShell.Run question
I have to ask (even if it may seem too obvious ;-)...

Do you escape the \'s in the JScript string literal?

Here's what I would do to debug:

cmd ='%comspec% /k ';
cmd+=' c:\\perl\\bin\\mhonarc.bat ';
cmd+=' f:\\mailarc\\in -add ';
cmd+=' -rcfile f:\\mailarc\\zak.rc ';
cmd+=' -mhpattern "^*.CNM" ';
cmd+=' -outdir f:\\mailarc\\out ';

WScript.echo(cmd);
WshShell.Run(cmd,1,true);

When all is well, take out the echo, change the /k switch to /c, and change the 2nd arg to Run to 0
(hidden).

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup...
--

Quote:

> Hi Reino,

> > Please publish your code so I could debug it.

> Unfortunately, the code is on a remote server. I can't get it 'till next
> week. The command line is exactly as stated, and is passed as a string
> to WshShell.Run() in JScript.

> --
> Gerry Hickman (London UK)



Sun, 18 May 2003 03:00:00 GMT  
 WshShell.Run question
Hi Michael,

Quote:
> I have to ask (even if it may seem too obvious ;-)...

> Do you escape the \'s in the JScript string literal?

Hmmmmmm, now that would be extremely dumb of me but quite possible! I'll
check it out thanks.

--
Gerry Hickman (London UK)



Mon, 19 May 2003 03:00:00 GMT  
 WshShell.Run question
Hi,

Quote:
> I have to ask (even if it may seem too obvious ;-)...

> Do you escape the \'s in the JScript string literal?

Turns out they _were_ escaped, but your syntax is more readable (using
single quotes).

Quote:
> Here's what I would do to debug:

> cmd ='%comspec% /k ';
> cmd+=' c:\\perl\\bin\\mhonarc.bat ';
> cmd+=' f:\\mailarc\\in -add ';
> cmd+=' -rcfile f:\\mailarc\\zak.rc ';
> cmd+=' -mhpattern "^*.CNM" ';
> cmd+=' -outdir f:\\mailarc\\out ';

> WScript.echo(cmd);
> WshShell.Run(cmd,1,true);

> When all is well, take out the echo, change the /k switch to /c, and

change the 2nd arg to Run to 0

Quote:
> (hidden).

Right, it seems you've solved this, and it all hinges on "%COMSPEC%".

Basically, the script runs correctly PROVIDED comspec is the first thing in
the command line. If I take out the comspec, it seems impossible to run this
command due to the double quotes around the -mhpattern parameter. I tried
other non-quote ideas instead but nothing works at the PERL level without
them.

I still have a question; despite changing to /c after comspec, the batch
file window still opens on screen while the BAT file is running - I don't
mind this, but I hope to eventually run this on a logged out NT Server as a
scheduled task. Does it matter if this window tries to pop up?

--
Gerry Hickman
Zak Travel Tech Support

(Note: my e-mail is fake is newsgroup postings)



Thu, 22 May 2003 03:00:00 GMT  
 WshShell.Run question

Besides changing %comspec% /k to %comspec% /c
did you change

WshShell.Run(cmd,1,true);

to

WshShell.Run(cmd,0,true);

0 = hidden window
1 = normal (visible) window

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> Hi,

> > I have to ask (even if it may seem too obvious ;-)...

> > Do you escape the \'s in the JScript string literal?

> Turns out they _were_ escaped, but your syntax is more readable (using
> single quotes).

> > Here's what I would do to debug:

> > cmd ='%comspec% /k ';
> > cmd+=' c:\\perl\\bin\\mhonarc.bat ';
> > cmd+=' f:\\mailarc\\in -add ';
> > cmd+=' -rcfile f:\\mailarc\\zak.rc ';
> > cmd+=' -mhpattern "^*.CNM" ';
> > cmd+=' -outdir f:\\mailarc\\out ';

> > WScript.echo(cmd);
> > WshShell.Run(cmd,1,true);

> > When all is well, take out the echo, change the /k switch to /c, and
> change the 2nd arg to Run to 0
> > (hidden).

> Right, it seems you've solved this, and it all hinges on "%COMSPEC%".

> Basically, the script runs correctly PROVIDED comspec is the first thing
in
> the command line. If I take out the comspec, it seems impossible to run
this
> command due to the double quotes around the -mhpattern parameter. I tried
> other non-quote ideas instead but nothing works at the PERL level without
> them.

> I still have a question; despite changing to /c after comspec, the batch
> file window still opens on screen while the BAT file is running - I don't
> mind this, but I hope to eventually run this on a logged out NT Server as
a
> scheduled task. Does it matter if this window tries to pop up?

> --
> Gerry Hickman
> Zak Travel Tech Support

> (Note: my e-mail is fake is newsgroup postings)



Thu, 22 May 2003 03:00:00 GMT  
 WshShell.Run question

Quote:
> Besides changing %comspec% /k to %comspec% /c
> did you change

> WshShell.Run(cmd,1,true);

> to

> WshShell.Run(cmd,0,true);

> 0 = hidden window
> 1 = normal (visible) window

Duh, no I forgot to do that! I'll give it a try.

I've written to the author of MHonArc asking about this parameter that
needs to be in double quotes. I'm trying to determine if this is a
generic problem for any such command line parameter, or whether it's
specific to the MHonArc mail archiver.

I only found one issue relating to this on MSDN, and it described a
problem passing a parameter that needs to be in double quotes, but this
was in relation to setup scripts (inf files) not the WSH.

This has all made me wonder exactly what goes on behind the scenes with
WshShell.Run? I wouldn't mind checking out the C++ or API docs for the
functions it calls as this isn't the first problem I've encountered.

--
Gerry Hickman (London UK)



Thu, 22 May 2003 03:00:00 GMT  
 WshShell.Run question
The Run method is basically just a wrapper around the Win32 API
ShellExecuteEx() function

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> > Besides changing %comspec% /k to %comspec% /c
> > did you change

> > WshShell.Run(cmd,1,true);

> > to

> > WshShell.Run(cmd,0,true);

> > 0 = hidden window
> > 1 = normal (visible) window

> Duh, no I forgot to do that! I'll give it a try.

> I've written to the author of MHonArc asking about this parameter that
> needs to be in double quotes. I'm trying to determine if this is a
> generic problem for any such command line parameter, or whether it's
> specific to the MHonArc mail archiver.

> I only found one issue relating to this on MSDN, and it described a
> problem passing a parameter that needs to be in double quotes, but this
> was in relation to setup scripts (inf files) not the WSH.

> This has all made me wonder exactly what goes on behind the scenes with
> WshShell.Run? I wouldn't mind checking out the C++ or API docs for the
> functions it calls as this isn't the first problem I've encountered.

> --
> Gerry Hickman (London UK)



Thu, 22 May 2003 03:00:00 GMT  
 WshShell.Run question

Quote:
> The Run method is basically just a wrapper around the Win32 API
> ShellExecuteEx() function

OK thanks. I'll check it out.

Amazingly the %comspec% idea has also fixed my broken HTA at home.

I'd been experiencing problems under Windows 2000 running a shortcut
(*.LNK), whereby using WshShell.Run was causing the EXE file to appear in a
file viewer instead of executing!

I can only imagine this was being caused by a registry problem. The file
viewer (Quick View Plus) installs a right click shell extension to every
file on the system, and maybe this has somehow conflicted with WshShell.Run.
No other aspect of the computer appears to be affected.

However, putting %comspec% as the first parameter of the WshShell.Run
command line has fixed the problem! Anyone know what might be happening
here?

--
Gerry Hickman
Zak Travel Tech Support

(Note: my e-mail is fake is newsgroup postings)



Fri, 23 May 2003 03:00:00 GMT  
 WshShell.Run question

Quote:
> However, putting %comspec% as the first parameter of the WshShell.Run
> command line has fixed the problem! Anyone know what might be happening
> here?

Further testing reveals a new issue; using %comspec% means you loose the
return value from the process you are trying to run.

It appears the return value from the child process does not propogate up
through the chain...

--
Gerry Hickman
Zak Travel Tech Support

(Note: my e-mail is fake is newsgroup postings)



Fri, 23 May 2003 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. WshShell.Run Question

2. WSHShell.run question

3. WshShell.Run vs WshShell.Exec

4. runas with WshShell.Exec versus WshShell.Run

5. wshshell.run: I can't run when there is a space in the path

6. Running COMMAND.COM with WshShell.Run

7. WshShell.Run don't run WHY ???

8. Batch file won't run with WshShell.run

9. Redirect WshShell.Run Output ?

10. Returning WshShell.Run Error Levels

11. Proffesional Help Needed: Unwanted Security Prompt W/ WshShell.run from local html

12. WSHShell.run and ActiveX script security dialog.

 

 
Powered by phpBB® Forum Software