Script hangs when reading output of command inside vbscript

Following code hangs  after the line "4 Go" but only on windows 2003.
Set objShell = CreateObject("WScript.Shell")
wscript.echo "2 Go"
backupstate = "wmic PATH WIN32_SERVICE where (name='vss') GET state"
wscript.echo "3 Go"
Set objExecObject = objShell.Exec(backupstate)
wscript.echo "4 Go"
With objExecObject
Do While .Status=0
Wscript.Sleep 10
Do While Not .StdOut.AtEndOfStream
strText = .StdOut.ReadLine()
If Not .StdErr.AtEndOfStream Then
.StdErr.ReadLine
End If
Loop
Loop
End With
Same code works perfectly fine on Windows 2008 and above.
Any suggestion?
-KAKA-

Your script hangs (or more precisely: it keeps looping) because the Exec method of of the Shell object is notoriously unreliable when it comes to detecting the status of the executable it invokes. You can easily find out by placing the line
wscript.echo "Status=" & objExecObject.status
inside your loop. This only works properly if you run the script with cscript.exe.
As Frederik says. :)
To explicitly answer why that MSKB article suggests continually emptying the error buffer, it's because doing so is better than
not doing so.
Another workaround I use in preference to embedding the console tool within a WSH script is to factor out the tool so I don't have to manipulate it internally; instead I pipe the output in to the script.
For example, suppose your script is named ProcessWmicOutput.vbs. within the script you would do something like this:
data = WScript.Stdin.ReadAll
to get all the data from wmic into a variable named data . Alternatively, you would do something like this, line by line (I'm making the script just relay StdOut from wmic):
Do While Not WScript.StdIn.AtEndOfStream
WScript.StdOut.WriteLine WScript.StdIn.ReadLine()
Loop
To run the script, getting wmic data, you would do this at a command prompt:
wmic PATH WIN32_SERVICE where (name='vss') GET state | cscript ProcessWmicOutput.vbs

Similar Messages

  • RMAN hangs when started at Linux command promp

    Running 9.2.0.4 on Red Hat Linux 8.0. Has anyone experienced RMAN hang when "rman" entered at command prompt?
    Thanks!

    Ah!!!! I think I had the same once! Use the linux command 'which rman' to determine what it is actually running! I bet it is some dodgy linux program instead. Change your PATH settings

  • Firefox hangs when reading data into a form

    I built a database-driven website which allows a user to change text and pictures thru a series of text boxes in a form. Firefox can take up to 2 minutes to populate the form from the database while all other Mac browsers take just a second or two. I've reset firefox and reinstalled it and started in Safe Mode, but no changes.
    I'd like to keep using Firefox but it doesn't work.

    Sorry, I don't want to sound as if I was "blowing you off" ....
    Are you familiar with the developer tools that are built into Firefox?
    https://developer.mozilla.org/en-US/docs/Tools/Tools_Toolbox
    https://developer.mozilla.org/en-US/docs/Tools
    Might help you figure out what Firefox "is choking on".
    Also, a live example URL of that webpage would be helpful when you post over at the MozillaZine fora.

  • Adobe reader XI crash and hangs when open the pdf file

    After update the adobe reader xi 11.0.10, the reader always crashes and hangs when open the pdf file. Please help me how to do.

    Ben Leung wrote:
    HThis situation is started after I clear the pop up advertisement.
    What kind of advertisement?  In Adobe Reader?  Can you post a screenshot of that: https://forums.adobe.com/thread/1070933
    Regarding the crash, can you try disabling Protected Mode through the registry: download, unzip, then run the registry script https://files.acrobat.com/a/preview/49eeb48b-07c5-4502-984c-8a25259914fa

  • Reading output from a Solaris(UNIX) shell script

    Hello All, I have written some fairly large shell scripts. I have also written a simple java GUI that contains a button that will run the script. The script runs. The problem is that I cannot see the output from the script in the x-term that I used to run my java class file.
    I am developing in a windows environment, I have a silly little system.out that prints "Button Pressed", which works in windows just fine but on my ultra 10 running Solaris 8 the term just sits there no output to the srceen.
    Has anyone out there solved this problem or know of a way that I can? Thanks

    I don't know how to print out to the x-term. But you can add a JTextArea to the GUI and get the output there.
    String output = null;
    StringBuffer returnString = new StringBuffer();
    String command = /path/to/shell/script/script.sh
    process = Runtime.getRuntime().exec(command);
    InputStreamReader isr = new InputStreamReader (process.getInputStream());
    input = new BufferedReader(isr);
    while((output = input.readLine()) != null){
        returnString.append(output);
    }Wouldn't a System.out.println(returnString.toString()) print to the x-term console?
    hope this helps.

  • Adobe Reader 10.1.2 (w/fix) and/or 9.x hang when printing.

    I've uninstalled/reinstalled both reversions many times (w/ and w/o 10.1.2 print fix).  The thing is, when first installed, both versions print okay, but after computer re-start/reboot printing a pdf file causes a hang of reader.  Word, excel, notepad, etc. print just fine.  As far as I can tell, duplex mode is not on in 10.1.2.  To get a pdf to print, I have to uninstall one version and reinstall another.  But it's a one session deal.  As soon as computer is rebooted, no printing.  Seems as if computer startup switches some setting.  OS is Windows XP with drivers up-to-date. Any suggestions?

    Repair did not correct it.  I used Revo Uninstaller to do a clean uninstall.  It uninstalls using the application's uninstall and then scans for any leftover files or registry entries. It found some so I got rid of them as well.  I deleted my temp files (%temp%) and emptied the recycle bin.  Then I donwloaded and installed Adobe Reader 10.1.2 from the web site.  It works!  I am so happy as I have many long PDFs and use search constantly.   Thank you for all your help.

  • Latest Reader Hangs when opening any pdf with 'tools' selected

    Any pdf will hang when opened in the latest Acrobat Reader (Either from file or open Acrobar Reader first.)
    However if I first open Reader and turn off the tools (Tools top right) I can then open any pdf without problems.
    Users who want to have the tools bar open are querying this.
    Can anyone help.
    Windows 7 64 bit systems.

    Try disabling Protected Mode [Edit | Preferences | Security (Enhanced)].

  • Reader X hangs when printing

    Have not been able to print from Reader X since installing.
    Windows XP to network printer. Reader X just hangs when spooling to the printer. I am able to print from other PDF programs (Foxit and Sumatra). Drag and dropping files to the printer after printing a page from the other programs will open Reader X for the other PDF documents and print but cannot print directly from Reader.
    Any ideas?
    James

    It is a network Konica/Minolta scan/fax/copy bizhub 200 served through SBS2003 server.
    Reader does not seem to print to any of the printers on the network - again, no problems with other programs. This includes Canon and HP printers too.
    James

  • Macbook (black) first edition hangs when trying to read Serial-ATA

    My Macbook recently died on me. In thinking it was my hard disc I have installed a new one. It did find it briefly when trying to install Snow Leopard again this failed since it could not communicate with the hard disc. Now I am stuck, using the System Profiler it just hangs when trying to read the Serial-ATA device tree.
    Any idea of what is wrong and if it is worth repairing it?
    with kind regards,
    Christian

    Turns out that the brand new Seagate that I got was faulty. Have now installed yet another drive and this seems to have done the trick.

  • My computer hangs when I use help menu command

    Is there a problem with the LabView help command when help is launched from a dialog box? My computer will hang when I do this and I must reboot to recover. I can't access any other program, including task manager.

    Hi,
    How exactly are you launching the LabVIEW help?  Furthermore, is there a .cpp error associated when trying to open up the help file?  Are you able to open up the help file directly through windows explorer by going to: C:\Program Files\National Instruments\LabVIEW 8.2\help  >>lvhelp.chm
    I hope this helps
    Regards,
    Nadim
    Applications Engineering
    National Instruments

  • Known issue: Cortana terminates when typing a voice command for an app (Windows 10 Insider Preview SDK and tools, April 2015 release)

    When typing a voice command for an app, e.g., "Find mom on MyApp", Cortana terminates without executing the voice command.

    Use the microphone to input voice commands for your app.

  • IE 5.0 hanging when one is reading HTML from Weblogic 6.0

    I have following configuration:
    Local network (TCP/IP, Wins server)
    SERVER: NT 2000 AdvServer & Weblogic Eval 6.0 Sp2 & Oracle 8.1.7
    CLIENTS
    1) Win 2000Pro & IE 5.0
    2) Win 98 & IE 5.0
    Quite often IE (client one) is hanging when one is reading static HTML pages.
    Also IE (client two) says that there is fail in Kernel and display dump of memory.
    In last case it is occured less often.
    I located these static HTML pages in Webdefault catalog.
    Also I have two simple JSP pages, one of them is genering current time and is
    working constantly.
    This situation was not changed when I did the following:
    1. Disable Java Plugin
    2. Set Weblogic Sp1.
    What did I wrong?
    Thanks in advance
    Eugenia
    [email protected]

    I play the mp3 files as sprites in the score that are
    streaming from the web server. If you selecr "Insert->Media
    Element->Shockwave Audio" from the menu in Director you can
    choose to import a mp3/swa file. This file will import as a cast
    member which will have an external link address. (e.g.
    http://www.adobe.com/mysound/myfile.mp3)
    I have then dragged this cast member onto channel 1 in the score
    spanning for instance 10 frames.
    It does not make a difference wether the soundfile is of type
    mp3 or swa, I have tried both.

  • Name error when executing WLST commands inside a jython class

    I am writing some reusable jython classes to be used to retrieve the health of a weblogic domain using WLST.
    But when I use simple WLST commands like connect() within a method connect() and the higherlevel jython script creates a object of WeblogicHealth() and calls connect(), I get NameError pointing to line with connect(). for some reason the namespace within my higher level script doesnt seem to recognize WLST commands.
    AM I doing something plain wrong?
    My class is as follows
    class WeblogicHealth:
    def init( resourceName ):
    def connect(userid,password,adminUrl)
    connect(userid,password,adminUrl)
    test_connect.py
    wlhealthObj = WeblogicHealth('server1')
    wlhealthObj.connect('user',password''url')
    I am running test_connect.py using command
    java weblogic.WLST test_connect.py
    and I get the nameError.
    PLease help

    http://download.oracle.com/docs/cd/E12840_01/wls/docs103/config_scripting/using_WLST.html#wp1094333

  • Sudo command hangs when run as winbind user

    Hi,
    It even hangs when running:
    $ sudo
    or
    $sudo -V
    So nothing to do with my sudo config - have reverted /etc/sudoers back to default. Even control-c does not work and the process needs to be killed as root, using another session.
    The command works fine when ran as a local user. It is only when running as a winbind user that there's a problem.
    Any help on what tools can be used to find out what's happening while the command is hanging would be much appreciated. Or even better any ideas on how to stop it hanging would be even better!
    Can provide any config files if they help anyone.......
    Many Thanks,
    Richard

    *** UPDATE ***
    It seems the version of sudo (v1.8*) supplied with Solaris 11 is not compatible with Winbind users.
    Workaround:
    Compile version 1.7* to /usr/local/bin and add this to the beginning of $PATH

  • Socket reading: hanging when using java, but OK when using javaw

    Tested and experienced on:
    Windows 2000 Workstation, Windows XP SP1
    jdk build 1.4.1_02-b06, build 1.4.2_04-b04
    My app is a GUI application. I am creating a socket like this:
    Socket socket = new Socket();
    socket.connect(new InetSocketAddress(proxy_host, Integer.parseInt(proxy_port)), 8000);
    BufferedReader in =
      new BufferedReader(
      new InputStreamReader(socket.getInputStream()));
    PrintWriter out =
      new PrintWriter(
       new BufferedWriter(
        new OutputStreamWriter(socket.getOutputStream())),true);
    String request = "GET url HTTP/1.1\r\n" +
                     "Accept: *\r\n" +
                     "Host: host\r\n" +
                     "Cookie: " + sessionCookie + "\r\n" +
                     "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; YComp 5.0.0.0)" + "\r\n" +
                     "Content-type: application/x-www-form-urlencoded" + "\r\n\r\n";
    out.print(request);
    out.flush();
    String str = "";
    while((str = in.readLine()) != null)
    socket.close();I am reading a HTML document from server. If I use the call
    java -jar MyJar.jar
    the reading starts hanging by reading the list line of the document. By call
    javaw -jar MyJar.jar
    all is fine. What could be the problem. I am really perplexed!

    Sounds like perhaps a timing issue. But a bigger issue is why aren't you simply using the higher-level java.net.URL, HttpURLConnection classes? You're reinventing the wheel here by writing low-level socket calls with HTTP protocol strings.

Maybe you are looking for

  • ITunes won't recognize iPod nano 6th gen

    I don't know how to get an I pod to connect to iTunes. iTunes will recognize all my other iPods the one I'm trying to connect is the same as one that's already connected

  • Importing cells and formulas from Excel?

    We are currently using Excel for our time sheets. We are trying to get away from that and are looking into using Adobe reader for our users to fill in their information. We use LiveCycle to design our forms, and I was wondering if there was a way to

  • Apple TV in dorm room

    I live in a college apartment and am thinking about getting an Apple TV so we can watch all of the movies/tv shows that are in my iTunes on our tv. Our campus wireless network is not password WEP password, but requires a login page be filled out (muc

  • Difficulty making a accurate teardrop shape

    Hi, My difficulty is based around making a tear drop shape on illustrator. I am using two shapes to make this, a square and circle (shown in attachment) however the accuracy is poor because the circle and square don't line up. I used a grid but still

  • Not receiving Return Label in email

    Hi Best Buy.. I am inquiring about an issue I have regarding acquiring a return label. I had purchased a TV on bestbuy.com, it had arrived with some Stuck Pixels on the screen and I requested a replacement TV. This was easy, and while on the phone I