Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
83 views
in Technique[技术] by (71.8m points)

javascript - 'sed' Command doesn't work with java script

I want to exectue following Shell Command with the Execute Option form Javascript:

"sed -i 4r<(sed '1,5!d' /etc/wpa_supplicant/wpa_template.template) /etc/wpa_supplicant/wpa_supplicant.conf"

Then i try this command in the shell console it works perfektly. But after starting it with the .js programm nothing is happen. I just want to copy the first 5 lines in template and add them to the config file.

question from:https://stackoverflow.com/questions/65937249/sed-command-doesnt-work-with-java-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do with exec from child_process

const exec = require('child_process').exec
exec("sed -i 4r<(sed '1,5!d' /etc/wpa_supplicant/wpa_template.template) /etc/wpa_supplicant/wpa_supplicant.conf", (err, stdout, stderr) => {
    if (err) {
       return console.error(err)
    }
    console.log(`stdout: ${stdout}`)
    console.log(`stderr: ${stderr}`)
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...