Comments (6)
I'm writing a PR for this but its going to take some time because it will need so much testing.
Some day maybe you can explain to me your use case for not using .ps1 scripts while using multi line?
from child-shell.
👍
If I were you, I would abandon the parameter feature of addCommand
. There are a lot of complicated cases and with the advent of string template literals, the user can figure out their own parameter passing mechanism pretty easily.
from child-shell.
I agree and you can essentially bypass it by just passing in one string for example:
ps.addCommand(`./remove-adGroupMember.ps1 -user '${user2}' -group '${groupDN}' -i ${i}`);
I arrived at this running mainly .ps1 scripts and having a lot of struggles with the interpretation of ' " and ` by the parameter logic
from child-shell.
I have a fork of node-powershell and I made a new branch: multi-line-suppor
https://github.com/BenjaminMichael/node-powershell/tree/multi-line-suppor
it seems to be working for this basic example:
const powershell = require('./node-powershell');
let ps = new powershell({
executionPolicy: 'Bypass',
noProfile: true,
multiLine: true
});
ps.on('output', output => {
console.log(output);
})
ps.addCommand(`$x = @"`);
ps.addCommand(`foo`);
ps.addCommand(`bar`);
ps.addCommand(`"@;`);
ps.invoke()
ps.addCommand(`$x | out-host`)
ps.invoke()
let ps2 = new powershell({
executionPolicy: 'Bypass',
noProfile: true
});
ps2.addCommand(`$PSVersionTable.PSVersion`);
ps2.addCommand(`$PSVersionTable.PSEdition`);
ps2.invoke()
.then(output => {
ps2.dispose();
console.log(output);
})
results in
NPS> Process 5928 started
NPS> Command invoke started
NPS> $x = @"
foo
bar
"@;
NPS> Command invoke started
NPS> $x | out-host
NPS> Process 240 started
NPS> Command invoke started
NPS> $PSVersionTable.PSVersion; $PSVersionTable.PSEdition
foo
bar
NPS> Command invoke finished
NPS> Command invoke finished
NPS> Command invoke finished
Major Minor Build Revision
----- ----- ----- --------
5 1 14393 1944
Desktop
NPS> Process 240 exited with code 0
It would be trivial to make a parser function that breaks down multi line JS strings into multiple addCommands. Is the goal to enter:
const x = `$x = @"
foo
bar
"@`;
addCommand(x);
and are you trying to compose with it?
addCommand(`${x} | out-host`);
I think it would help to see an example where this gives a benefit
from child-shell.
I don't see the benefit of creating a call to addCommand
per line. That seems unnecessarily repetitive.
What I was trying to do,
addCommand(`
$value = @"
${JSON.stringify(req.params)}
"@
`);
from child-shell.
That seems more of an implementation detail. This example works and it takes any number of commands separated by commas so I added an out-host command to show its working. It seems to work.
const powershell = require('./node-powershell');
const addThenInvokeMLCommand = (...multiLineCommand) =>{
this.ps = new powershell({
executionPolicy: 'Bypass',
noProfile: true,
multiLine: true
});
this.ps.on('output', output => {
console.log(output);
});
this.ps.on('end', code => {
this.ps.dispose();
});
multiLineCommand.forEach((line) => {
const commandArray = line.split('\n');
commandArray.forEach((val) => {
this.ps.addCommand(val + `\n`);
});
});
this.ps.invoke();
}
const myJSON = {
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}
addThenInvokeMLCommand(`
$value = @"
${JSON.stringify(myJSON)}
"@
`, `$value | out-host`);
from child-shell.
Related Issues (20)
- invoke promise not always executed
- 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
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.