Comments (8)
Could the behavior reported in this issue possibly be related to that reported in #20?
from child-shell.
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.
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.
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.
@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.
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.
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.
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)
- Allow for PWSH Custom Paths
- proper use of ps.dispose HOT 1
- PS_CMD_FAIL_ERROR: Error code = 0x80005000 HOT 1
- [Node-Bash] Command invocation failed
- Documentation page doesn't work HOT 3
- TypeError: shell is not a constructor HOT 7
- NPS> PS process ***** exited with code 4294901760
- getting powershell output back into javascript HOT 5
- Run without PS
- How to avoid arbitrary command injection
- Text decoding error when returning to resolve characters containing non-English HOT 1
- Documentation links fail HOT 1
- How to use Child-Shell HOT 4
- broken readme links please validate
- debug does not export Debugger
- debug does not export Debugger;
- ProcessError: Shell process (somePID) exited. originalError: undefined, exitCode: null, signalCode: 'SIGABRT'
- Is repo still maintained? HOT 3
- await PowerShell.$`${myVariable}` always stuck
- .addCommand not a valid method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from child-shell.