Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda