Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!