However, if I get a -2 but then I run the command from a command prompt, it works, which leads me to believe that I am fighting an environmental problem. The first thing I would find out is if these exit codes are documented somewhere.

Run "notepad", 1, true. Forgive my shorthand, but I am doing the correct thing. Shell is null or is not an object. Yes the code I posted was shorthand.

In Vbsedit, you only need to press F1 to get Help for the keyword under the cursor!

The code I am running is doing the correct thing as evidenced by the lack of a JScript runtime error. So to stop this nonsense, this is what I am really doing:. Run "WBAdmin So we know that r is the return code from the program. If you are getting a return code of -1 or -2, the likely interpretation is that JScript is interpreting r as a signed rather than as an unsigned integer.

The first step is always read the docs and when they are silent, the second step is to ask your friends. The docs don't give any details of the status code from the "run" command; I've looked. If I missed it, then I would be most grateful if you would show me where it is.

Or you could even cut the suspense and tell me what -1 and -2 mean? The radix of the status code is not very important if I don't have any explanations of any status codes.

So we know that in your case, r is the exit code from wbadmin. The interpretation of that error code depends entirely on that program. To find out what those exit codes mean, you would need to look up the documentation for wbadmin.

Ribosome structure in prokaryotes

In that case teh return code may not be what you expect. If you use the correct or at least usab;e ActiveX activation then teh returncode would be meaningful. Almost all programs return positive result codes or negative values that map to hex values between 0x oxFFFF. I have never seen or heard of an exception or error code that is higher than that.

I was pretty sure that the -1 and -2 were not really scripting issues and I said as much in my original post. The second paragraph points out the inconsistency of a -2 return from the "run" command and the same command running from a command prompt and running successfully and raises the question of the scripting environment compared to the command prompt environment. That is the real question here. More importantly, how do I go about diagnosing this? After some more consideration, I am willing to bet I have a permission problem and that is what -2 means.

This is easy to test, and I will test this first thing tomorrow and tell you want I learn.String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script.

If set to truescript execution halts until the program finishes, and Run returns any error code returned by the program. If set to false the defaultthe Run method returns immediately after starting the program, automatically returning 0 not to be interpreted as an error code. The Run method returns an integer. The Run method starts a program running in a new Windows process. You can have your script wait for the program to finish execution before continuing. This allows you to run scripts and programs synchronously.

Environment variables within the argument strCommand are automatically expanded. If a file type has been properly registered to a particular program, calling run on a file of that type executes the program. The following table lists the available settings for intWindowStyle. Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

Activates and displays the window. An application should specify this flag when restoring a minimized window. The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down. WshShell Object. The active window remains active. The following VBScript code opens a copy of the currently running script with Notepad. CreateObject "WScript.

Shell" WshShell. ScriptFullName, 1, true. CreateObject "WSCript. Applies To: WshShell Object.Join Stack Overflow to learn, share knowledge, and build your career. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

You will want to use the WshShell object's Exec method instead of Run. Then simply read the command line's output from the standard streams. Try this one:.

Programming the Windows Script Host

This is a modified version of Nilpo's answer that fixes the issue with WshShell. Exec being asynchronous. We do a busy-loop waiting until the shell's status is no longer running, and then we check the output. Change the command-line argument -n 1 to a higher value to make ping take longer, and see that the script will wait longer until completion.

If anyone has a true asynchronous, event-based solution to the problem, then please let me know! The solution of BoffinBrain still doesn't work, since exec. Status doesn't return an error level returns just 0 while running and 1 when finished.

For that purpose you must use exec. ExitCode Returns the exit code set by a script or program run using the Exec method.

javascript wscript shell run return value

So the solution changes to. Learn more. Asked 9 years, 8 months ago. Active 7 months ago. Viewed 69k times. CreateObject "WSCript. Improve this question. Nilpo 4, 1 1 gold badge 20 20 silver badges 36 36 bronze badges.

javascript wscript shell run return value

Cocoa Dev Cocoa Dev 8, 28 28 gold badges silver badges bronze badges. Define "results". Runas exit code? Exit code of the application run via runas? The application's console output? Active Oldest Votes. Write strOutput 'write results to the command line WScript. Echo strOutput 'write results to default output MsgBox strOutput 'write results in a message box. Improve this answer. Nilpo Nilpo 4, 1 1 gold badge 20 20 silver badges 36 36 bronze badges.

Subscribe to RSS

Would we be able to do the same kind of thing with WshShell.Log In. Join your peers on the Internet's largest technical computer professional community. It's easy to join and it's free. Register now while it's still free! Already a member? Close this window and log in. Join Tek-Tips Forums! Join Us! By joining you are opting in to receive e-mail. Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here. Language Reference How can one script pass and return values to another script? CreateObject "WScript. Item 0 Msgbox Wscript. Item 1. Environment "User" If objShell. Item 0 If objShell.

Urbano express sonsonate el salvador

My Archive. Close Box.

Atms you can withdraw 1000

Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden. How can one script pass and return values to another script?

Translate to russian from arabic

In my experiences, I have found that there are basically three ways to accomplish this task. Each method has its own pros and cons, so the developer will need to determine which method best suites their needs. Most scripting developers know about the shell object provided to us by Microsoft. If you do not know about this object, then I recommend that you gather that information before continuing with this FAQ.

Here is a simple program calling another program named called.Join Stack Overflow to learn, share knowledge, and build your career. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm running my JScript file using cscript. In the script I need to call an external console command and get the output. ReadAll; line. You can also use the WshScriptExec object and read the StdOut property, but if you use that object you can't control the window state like you can with WshShell.

Run like above. Learn more. JScript: how to run external command and get output? Ask Question. Asked 6 years, 7 months ago. Active 6 years, 7 months ago.

Viewed 16k times. CreateObject "WScript. Status ; WScript. ProcessID ; WScript. So, how should I do it? ReadAll; WScript. Improve this question.

Putnik Putnik 3, 3 3 gold badges 26 26 silver badges 41 41 bronze badges.

VBScript Basics, Part 5 - Run Command

Dariusz I've updated the question. Still doesn't work for me. Active Oldest Votes. Improve this answer. BuildPath fso. GetSpecialFolder 2fso.Orders delivered to U. Learn more. In Appendix C, "Automating Windows XP with Batch Files," you learn how to tame the command prompt by creating batch files —small, executable text files that run one or more commands.

You'll see that with a little ingenuity and a dash of guile, it's possible to make batch files perform some interesting and useful tasks. Indeed, for many years, batch files were the only way to automate certain kinds of tasks. Unfortunately, the batch file world is relentlessly command-line—oriented. So, with the exception of being able to launch Windows programs, batch files remain ignorant of the larger Windows universe. If you're looking to automate a wider variety of tasks in Windows, you need to supplement your batch file knowledge with scripts that can deal with the Registry, shortcuts, files, and network drives, and that can even interact with Windows programs via Automation.

This chapter introduces you to the Windows Script Host, shows you how to execute scripts, and runs through the various elements in the Windows Script Host object model. As you might know, Internet Explorer is really just an empty container application that's designed to host different data formats, including ActiveX controls, various file formats such as Microsoft Word documents and Microsoft Excel worksheetsand several ActiveX scripting engines.

A scripting engine is a dynamic link library DLL that provides programmatic support for a particular scripting language. This enables web programmers to write small programs— scripts —that interact with the user, control the browser, set cookies, open and close windows, and more.

Although these scripting engines don't offer full-blown programmability you can't compile scripts, for examplethey do offer modern programming structures such as loops, conditionals, variables, objects, and more.

Cinevood punjabi movie sufna

In other words, they're a huge leap beyond what a mere batch file can do. The Windows Script Host is also a container application, albeit a scaled-down application in that its only purpose in life is to host scripting engines.

However, Microsoft designed the Windows Script Host to be a universal host that can support any ActiveX-based scripting engine. Therefore, there are also third-party vendors offering scripting engines for languages such as Perl, Tcl, and Rexx.

The key difference between Internet Explorer's script hosting and the Windows Script Host is the environment in which the scripts run.

javascript wscript shell run return value

Internet Explorer scripts are web page—based, so they control and interact with either the web page or the web browser.

The Windows Script Host runs scripts within the Windows Vista shell or from the command prompt, so you use these scripts to control various aspects of Windows. Here's a sampling of the things you can do:. What about speed? After all, you wouldn't want to load something that's the size of Internet Explorer each time you need to run a simple script. That's not a problem because, as I've said, the Windows Script Host does nothing but host scripting engines, so it has much less memory overhead than Internet Explorer.

That means that your scripts run quickly. For power users looking for a Windows-based batch language, the Windows Script Host is a welcome tool.

javascript wscript shell run return value

This chapter does not teach you how to program in either VBScript or JavaScript and, in fact, assumes that you're already proficient in one or both of these languages. See All Related Store Items. FREE U. This chapter is from the book.

NOTE This chapter does not teach you how to program in either VBScript or JavaScript and, in fact, assumes that you're already proficient in one or both of these languages. Related Resources Store Articles. Join Sign In. All rights reserved.Shell Windows Script Host? Shell " objWSh. You must include any parameters you want ; to pass to the executable file. Integer value indicating the appearance of the program's window. Note that not all ; programs make use of this information.

Boolean value indicating whether the script should wait for the program to finish ; executing before continuing to the next statement in your script. If set to true, script execution ; halts until the program finishes, and Run returns any error code returned by the program. If set to ; false the defaultthe Run method returns immediately after starting the program, automatically ; returning 0 not to be interpreted as an error code.

The Run method starts a program running in a new Windows ; process. You can have your script wait for the program to finish execution before continuing. This ; allows you to run scripts and programs synchronously.

Environment variables within the argument ; strCommand are automatically expanded. If a file type has been properly registered to a particular ; program, calling run on a file of that type executes the program.

The ; following table lists the available settings for intWindowStyle. If the window is minimized or maximized, the system restores it ; to its original size and position. An application should specify this flag when displaying the ; window for the first time.

Vba get cell value to variable

The active window remains active. An application should specify this flag when restoring a ; minimized window. CreateObject "WScript. Shell" ; WshShell. ScriptFullNameThe following VBScript code does the same ; thing, except it specifies the window type, waits for Notepad to be shut down by the user, and ; saves the error code returned from Notepad when it is shut down.