Coder Social home page Coder Social logo

Comments (8)

mattflix avatar mattflix commented on June 18, 2024

Could the behavior reported in this issue possibly be related to that reported in #20?

from child-shell.

BenjaminMichael avatar BenjaminMichael commented on June 18, 2024

I do not think ls c: means what you think it means in powershell. I think you want
ls C:\

it works for me in this example:

const powershell = require('node-powershell')
 let ps = new powershell({
        executionPolicy: 'Bypass',
        noProfile: true
    });   
    ps.addCommand(`ls C:\\`) /* ps.addCommand("ls C:\\") also works */
    ps.invoke()
    .then(output => {
        console.log(output)
    })
    .catch(err => {
        console.log(err);
        ps.dispose();
    });

from child-shell.

mattflix avatar mattflix commented on June 18, 2024

Okay, I see that "ls c:" and "ls c:\" do list out different things. (The former lists the content of the current directory of drive C:, while the latter list the contents of the root directory.)

But, that's beside the point.

The point is, when entered manually at the command-line, both commands output something. But, with node-powershell, the output of "ls c:" is always an empty string (see all my examples in the original report above). That is the problem here... this missing output. No?

from child-shell.

BenjaminMichael avatar BenjaminMichael commented on June 18, 2024

I think you're experiencing a problem because youre attempting to use async/await and not the method described in the documentation

ps.invoke().then(output => {}).catch(err => {});

from child-shell.

mattflix avatar mattflix commented on June 18, 2024

@BenjaminMichael, manually calling .then() or letting await do it yields equivalent code. This has nothing to do with the behavior.

In any case, I have tried my old examples with the latest node-powershell (3.2) on my current version of Windows 10 (which is now build 1703; I was likely using an older build back when I filed this issue -- I was also using node-powershell 3.1).

In any case, I can no longer reproduce the behavior with either node-powershell 3.1 or 3.2 on Windows 10 1703. Perhaps this was a problem running on an older version of PowerShell?

Here is my current version of PowerShell:

> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      15063  674

Perhaps the library author should try my original examples on older versions of PowerShell to see if he can reproduce the behavior?

If the behavior is PowerShell version-related, and no longer occurs on later versions, the author may still wish to ensure that users of older versions of PowerShell don't run into this problem (that perhaps can be avoided or worked-around with a change to node-powershell). Or, at least warn users about the minimum version of PowerShell that is required for proper behavior.

from child-shell.

BenjaminMichael avatar BenjaminMichael commented on June 18, 2024

If you could provide a full example I can test it for you but I cant get your examples above to compile when I add const Shell = require('node-powershell')

Could you provide a full example? I apologize for my ignorance. I have a test environment up for toggling versions of PS(really WMF) and Node on Win7 and both Win10 1703 and 1607. I'm eager to help and even more eager to learn.

from child-shell.

mattflix avatar mattflix commented on June 18, 2024

Yes, my examples were just snippets, to compare the use-cases I was showing.

The complete version of my first example would be:

const Shell = require('node-powershell');

async function main() {
    const shell = new Shell({ debugMsg: false });
    await shell.addCommand("ls c:");
    const output = await shell.invoke();
    console.log(output);
}

main();

This should run as-is with later versions of Node (which support async natively).

from child-shell.

BenjaminMichael avatar BenjaminMichael commented on June 18, 2024

Do you only want to test old versions of PS since this is not expected to work on old versions of Node?

Also I was curious if this particular async/await syntax helps mitigate the race condition from Issue #28

from child-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.