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

189
Visualizações
Electron executing powershell script

I want to execute a powershell script on the start of the electron App. I tried to add the following into the <head> in my index.html :

<head>
<script type="text/javascript">
    var spawn = require("child_process").spawn;
    spawn("powershell.exe",[".\myPSScript.ps1"]);       
</script>
</head>
<body>
...
</body>

This did not work. When adding:

document.write("Hello")

it shows up in the app so I can be sure that the <script>is being run. When I run the script itself from powershell-terminal it runs with no issues and does what it should.

I also tried giving the absolute path in:

spawn("powershell.exe",["C:\folder\folder2\myPSScript.ps1"]);       

The script deletes all .db files in a folder on the machine.

Get-ChildItem -Path 'MY_Wonderfull_Path' *.db | Where-Object { $_.CreationTime -lt (get-date 2021-09-09) } | foreach { Remove-Item -Path $_.FullName }

I have no idea why it is not running. Is electron not able to spawn a new child process? Is it an issue with permissions?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As requested, here my comment as answer.

You need to double the backslashes in the path to escape them.

spawn("powershell.exe",["C:\\folder\\folder2\\myPSScript.ps1"]);
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