Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Execute Powershell script from Node.js with ES6 Modules enabled

I need to execute a Powershell file on my NodeJS server and the answer to that is allready given in this post.

However I am unable to replace const { exec } = require('child_process'); or var spawn = require("child_process").spawn; with the needed Import since my Server is running with ES6 Modules enabled in the package.json "type": "module"

Does anybody know how to properly import the needed Module in this specific case? Here is the code I was trying out on my server which are from the Users Honest Objections and muffel posted in this post:

Honest Objections Code:

const { exec } = require('child_process');
exec('command here', {'shell':'powershell.exe'}, (error, stdout, stderr)=> {
    // do whatever with stdout
})

muffel Code:

var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
child.stdout.on("data",function(data){
    console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
    console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
    console.log("Powershell Script finished");
});
child.stdin.end(); //end input
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can replace CommonJS imports

const { exec } = require('child_process');
var spawn = require("child_process").spawn;

with ES6 imports

import { exec } from 'child_process';
import { spawn } from 'child_process';

at module scope and with

const { exec } = import('child_process');
var spawn = import('child_process').spawn;

at function scope.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda