Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:23:38+00:00 2026-06-06T21:23:38+00:00

I was trying my hand at Windows shell scripting using cscript and Javascript .

  • 0

I was trying my hand at Windows shell scripting using cscript and Javascript. The idea was to take a really long Python command that I was tired of typing into the command line over and over. What I wanted to do was write a script that is much shorter to write the whole Python command into a Windows script and just call the Windows script, which would be a lot less to type. I just don’t know how I would go about calling a “command within a command” if that makes sense.

This is probably an easy thing, but I’m an newbie at this so please bear with me!

The idea:

Example original command: python do <something really complicated with a long filepath>

Windows Script: cscript easycommand

 <package id = "easycommand">
      <job id = "main" >
          <script type="text/javascript">
               // WHAT GOES HERE TO CALL python do <something really complicated>
               WScript.Echo("Success!");
          </script>
      </job>
 </package>

Thanks for all your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:23:39+00:00Added an answer on June 6, 2026 at 9:23 pm

    Here’s what I use

    function logMessage(msg) {
        if (typeof wantLogging != "undefined" && wantLogging) {
            WScript.Echo(msg);
        }
    }
    
    // http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx
    var windowStyle = {
        hidden    : 0,
        minimized : 1,
        maximized : 2
    };
    
    // http://msdn.microsoft.com/en-us/library/a72y2t1c(v=VS.85).aspx
    var specialFolders = {
        windowsFolder   : 0,
        systemFolder    : 1,
        temporaryFolder : 2
    };
    
    function runShellCmd(command, deleteOutput) {
        deleteOutput = deleteOutput || false;
        logMessage("RunAppCmd("+command+") ENTER");
        var shell = new ActiveXObject("WScript.Shell"),
            fso = new ActiveXObject("Scripting.FileSystemObject"),
            tmpdir = fso.GetSpecialFolder(specialFolders.temporaryFolder),
            tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName()),
            rc;
    
        logMessage("shell.Run("+command+")");
    
        // use cmd.exe to redirect the output
        rc = shell.Run("%comspec% /c " + command + "> " + tmpFileName,
                           windowStyle.Hidden, true);
        logMessage("shell.Run rc = "  + rc);
    
        if (deleteOutput) {
            fso.DeleteFile(tmpFileName);
        }
        return {
            rc : rc,
            outputfile : (deleteOutput) ? null : tmpFileName
        };
    }
    

    Here’s an example of how to use the above to list the Sites defined in IIS with Appcmd.exe:

    var
    fso = new ActiveXObject("Scripting.FileSystemObject"),
    windir = fso.GetSpecialFolder(specialFolders.WindowsFolder),
    r = runShellCmd("%windir%\\system32\\inetsrv\\appcmd.exe list sites");
    if (r.rc !== 0) {
        // 0x80004005 == E_FAIL
        throw {error: "ApplicationException",
               message: "shell.run returned nonzero rc ("+r.rc+")",
               code: 0x80004005};
    }
    
    // results are in r.outputfile
    
    var
    textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading),
    sites = [], item, 
    re = new RegExp('^SITE "([^"]+)" \\((.+)\\) *$'),
    parseOneLine = function(oneLine) {
        // each line is like this:  APP "kjsksj" (dkjsdkjd)
        var tokens = re.exec(oneLine), parts;
    
        if (tokens === null) {
            return null;
        }
        // return the object describing the website
        return {
            name : tokens[1]
        };
    };
    
    // Read from the file and parse the results.
    while (!textStream.AtEndOfStream) {
        item = parseOneLine(textStream.ReadLine()); // you create this...
        logMessage("  site: " + item.name);
        sites.push(item);
    }
    textStream.Close();
    fso.DeleteFile(r.outputfile);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a function that will take short hand hex color to
I'm fairly new to Python, so I'm trying my hand at some simple code.
I am developing a metro app using JavaScript and am trying to display two
I'm trying to use distutils with a Python module that contains extensions written in
I'm trying to run a particular JUnit test by hand on a Windows XP
I'm trying to make a function that can take an enum type, display all
I'm using Facebook's JavaScript SDK and trying to determine if the user is logged
I'm thinking about trying my hand at a Windows Phone 7 app, and I'd
I am trying my hand at writing an app for Windows 8. I want
I'm a .NET developer trying his hand at an OSX port of a Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.