Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WshShell.Exec fails

193 views
Skip to first unread message

sath

unread,
Oct 15, 2007, 10:50:00 PM10/15/07
to
I am trying run a C++ program from WshShell.Exec in a VB script.

dim updcmd
updcmd = "c:\\CPLUS\\DIAG C:\\cplus\\input\\test2.txt"
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(updcmd)
Do While oExec.Status = 0
WScript.Sleep 1000
Loop

The problem is, it processes 1000 records(out of 50K) and just hangs.
The program works fine from the command line.
Any help is greatly appreciated.

Thanks in advance.
Sath

Jason

unread,
Oct 16, 2007, 8:27:45 AM10/16/07
to

Try the Run option and enable the wait on return?
WshShell.Run updcmd, 1, 1

That eliminates your need to set a loop to sleep and wait on the
execution.

Pete Delgado

unread,
Oct 16, 2007, 9:26:41 PM10/16/07
to

"sath" <sa...@discussions.microsoft.com> wrote in message
news:09B60E08-B528-4157...@microsoft.com...

>I am trying run a C++ program from WshShell.Exec in a VB script.
>
> dim updcmd
> updcmd = "c:\\CPLUS\\DIAG C:\\cplus\\input\\test2.txt"

If this is VB script, you don't need to use the double backslash escape in
strings.

-Pete


TDM

unread,
Oct 19, 2007, 10:36:53 AM10/19/07
to

"Jason" <flaj...@gmail.com> wrote in message
news:1192537665.7...@y27g2000pre.googlegroups.com...

> On Oct 15, 10:50 pm, sath <s...@discussions.microsoft.com> wrote:
>> I am trying run a C++ program from WshShell.Exec in a VB script.
>>>> Sath
>
> Try the Run option and enable the wait on return?
> WshShell.Run updcmd, 1, 1
>
> That eliminates your need to set a loop to sleep and wait on the
> execution.
>

Or, since you are in a loop, and you are using the .Exec method,
why not process stdOut so you can see what is going on ?

dim updcmd
updcmd = "%comspec% /c c:\CPLUS\DIAG C:\cplus\input\test2.txt 2>&1"


Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(updcmd)
Do While Not oExec.StdOut.AtEndOfStream
WScript.Echo oExec.StdOut.ReadLine
Loop


TDM


sath

unread,
Oct 21, 2007, 7:24:00 PM10/21/07
to
Thanks Jason.
I tried the run option and it works.

Reventlov

unread,
Nov 3, 2007, 6:55:30 PM11/3/07
to
Il giorno Fri, 19 Oct 2007 07:36:53 -0700, "TDM" <rpu...@gmail.com> ha scritto:
>Or, since you are in a loop, and you are using the .Exec method,
>why not process stdOut so you can see what is going on ?
>
>dim updcmd
> updcmd = "%comspec% /c c:\CPLUS\DIAG C:\cplus\input\test2.txt 2>&1"
> Dim WshShell, oExec
> Set WshShell = CreateObject("WScript.Shell")
>
> Set oExec = WshShell.Exec(updcmd)
> Do While Not oExec.StdOut.AtEndOfStream
> WScript.Echo oExec.StdOut.ReadLine
> Loop

If I am not wrong, the help file says stdin and stdout work only in cscript. But in XP,
stdout is available in wscript too. This is great.

With win ME stdout in wscript causes an error.
Giovanni.
--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

Paul Randall

unread,
Nov 5, 2007, 11:26:24 AM11/5/07
to

"Reventlov" <no...@no.void> wrote in message
news:472cee08...@powernews.libero.it...

I suppose it is possible that the CScript/WScript difference could be
OS-related, but I think it more likely that it is due to a difference in the
scripting engine.

Do you get the same value on all machines with this statement?

WScript.Echo WScript.Version

-Paul Randall


Reventlov

unread,
Nov 11, 2007, 5:19:11 PM11/11/07
to
Il giorno Mon, 5 Nov 2007 09:26:24 -0700, "Paul Randall" <paul...@cableone.net> ha
scritto:

>> If I am not wrong, the help file says stdin and stdout work only in
>> cscript. But in XP,
>> stdout is available in wscript too. This is great.
>>
>> With win ME stdout in wscript causes an error.

>I suppose it is possible that the CScript/WScript difference could be

>OS-related, but I think it more likely that it is due to a difference in the
>scripting engine.
>
>Do you get the same value on all machines with this statement?
>
>WScript.Echo WScript.Version

it's 5.6 in win ME. I still have to check on XP pc's.

--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)

--

Paul Randall

unread,
Nov 12, 2007, 12:23:24 PM11/12/07
to

"Reventlov" <no...@no.void> wrote in message
news:473771bf...@powernews.libero.it...

Perhaps you are correct that it is a problem in older OSs.

-Paul Randall


kams senthil

unread,
Nov 13, 2007, 6:01:47 AM11/13/07
to

Hi ,
I am using javascript.
I want to execute a perl program.
can perl be direclty executed?

As of now I am using bat file containing the perl command
The code I use is on button click

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("%comspec% /c D:\GUP-501\rulegen1\t.bat");
WshShell.Quit;

-----------------------------
bat file is
perl D:\GUP-501\rulegen1\rulegenerator.pl -v V1 -t FS5K -f
D:\GUP-501\rulegen1\RgApplicationConfig.xml -b

This is not working, can anybody help me on it.

*** Sent via Developersdex http://www.developersdex.com ***

Reventlov

unread,
Nov 16, 2007, 5:45:33 PM11/16/07
to
Il giorno Sun, 11 Nov 2007 22:19:11 GMT, no...@no.void (Reventlov) ha scritto:

> "Paul Randall" <paul...@cableone.net>

>>> If I am not wrong, the help file says stdin and stdout work only in
>>> cscript. But in XP,
>>> stdout is available in wscript too. This is great.

>>I suppose it is possible that the CScript/WScript difference could be
>>OS-related, but I think it more likely that it is due to a difference in the
>>scripting engine.
>>Do you get the same value on all machines with this statement?
>>WScript.Echo WScript.Version

it's 5.6 in both XP and win ME.

The following script works in xp (Windows 5.1 service pack 2) with a double click.
In ME (on my pc is not very stable, recently) i get an error but I don't remember what it
says.

Set WshShell = CreateObject("Wscript.shell")
Set objExec= WshShell.Exec("%comspec% /c dir c:\")
output = objExec.StdOut.ReadAll
MsgBox output

but vbscript56.chm says (about readall method):
"
The StdIn, StdOut, and StdErr properties and methods work when running the script with the
CScript.exe host executable file only. An error is returned when run with WScript.exe.

Reventlov

unread,
Nov 16, 2007, 6:33:07 PM11/16/07
to
Il giorno Fri, 16 Nov 2007 22:45:33 GMT, no...@no.void (Reventlov) ha scritto:
>The following script works in xp (Windows 5.1 service pack 2) with a double click.
>In ME (on my pc is not very stable, recently) i get an error but I don't remember what it
>says.
>
>Set WshShell = CreateObject("Wscript.shell")
>Set objExec= WshShell.Exec("%comspec% /c dir c:\")
>output = objExec.StdOut.ReadAll
>MsgBox output

There is no error. But the msg box is empty with win ME. I got an error but it was due to
the SORT command I was calling in a different example.

Reventlov

unread,
Nov 25, 2007, 10:06:06 AM11/25/07
to
Il giorno Mon, 12 Nov 2007 10:23:24 -0700, "Paul Randall" <paul...@cableone.net> ha
scritto:

>Perhaps you are correct that it is a problem in older OSs.

Well, it's not a problem. I'm happy to access stdout even if the help file says it cannot
be done. It's very useful. It's a problem that I cannot use it at home on win ME.
Giovanni.

0 new messages