Comments (9)
Can you give an example that is not solved by using backticks ``
around your strings and is not typical of PowerShell's regular behavior?
from child-shell.
@BenjaminMichael do you mean me escaping my quotes before invoking PowerShell? If so, not really.
imo, I should be able to pass valid javascript strings to node-powershell and have it correctly format them for PowerShell. Safe by default.
I can see an argument for me having to escape the strings I pass to node-powershell too. I've done the work in my fork for my use case.
from child-shell.
No I'm saying use template strings which are new if you are unfamiliar with ES6. It will give you the equivalent value as if you escaped characters
`\`` === '`' // --> true
from child-shell.
If I escape the javascript string myself (ie insert `
before my quotes) the command execute fine. I feel a javascript library should be doing the escaping for me, since I pass in a valid javascript string. The fix was a simple: value.replace(/[\'\"]/g, '
$&');`.
In the current version this will hang:
string a = 'hsimah\'s';
string b = "hsimah's";
string c = `hsimah's`;
These will work:
string a = 'hsimah`\'s';
string b = "hsimah`'s";
string c = `hsimah\`'s`;
string d = 'hsimah\'s test'; // node-powershell wraps strings with whitespace in double quotes
from child-shell.
ps.addCommand(`write-host "hsimah's"`) //doesn't hang
This is just how PowerShell works.
edit: not trying to say that the PowerShell interpreter is perfect but if you go to the PowerShell github they can explain their choices better than I ever could.
edit2: a more generic example:
ps.addCommand(`write-host "${userName}"`) //doesn't hang
from child-shell.
Yes but if you use the parameter/value syntax it does hang:
ps.addCommand('my-cmdlet', [{Name: "hsimah's"}]); // hangs
Node-powershell doesn't wrap the value in quotes unless it contains a space. PowerShell is inferring it is a string, but it needs to be escaped with a backtick.
from child-shell.
My opinions are not those of Rann. I don't use the params as JSON I just always use template strings.
ps.addCommand(`./scripts/get-ADUser.ps1 -u1 ${payload.user1Name} -cu ${payload.currentUser}`);
In this example I don't even use quotes because I already sanitized the user names Im gathering. In my opinion these are merely implementation details. Since you made your own fork and your PR like you have people will see it and if they like it they will ask you to make an npm module (because Rann doesn't actively maintain node-powershell anyways).
from child-shell.
Yeah, I considered template strings, but some of the cim cmdlets get out of hand with the number of parameters. The array of objects was easier to use in that regard.
I'll add a test to see if my fork affects the pure string commands. I don't think it would as the logic flow is different, but I didn't check that and it's a bad PR if I break your code!
from child-shell.
@rannn505 I see this was closed. I no longer use node-powershell (changed jobs).
Is this fixed or not deemed necessary? I have an open PR related that can be closed either way.
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.