Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windowsHide: true does not work when using shell: true and detached: true #346

Closed
rynz opened this issue Jul 3, 2019 · 12 comments
Closed

Comments

@rynz
Copy link

rynz commented Jul 3, 2019

Operating System
Windows 7/8/10

Question
When running execa with shell: true is it possible to optionally hide the cmd window?

Cheers!

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

Hi @rynz, thanks for reaching out.

I am assuming you are talking about the new window created by cmd.exe when spawning a command. This new window should always be hidden with execa because we force windowsHide to be true.

Is your problem:

  1. that you would like to see that window?
  2. that you don't want to see that window, but it does appear (which it should not)?

@rynz
Copy link
Author

rynz commented Jul 3, 2019

Hi @ehmicky, love this project. My problem is number 2.

await execa(cmd, args, { shell: true, detached: true })

and the new window created by cmd.exe appears using electron.

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

If an additional cmd.exe window pops up, this is a bug indeed.

Could you try the following?

  1. Run instead child_process.spawn(cmd, args, { shell: true, detached: true, windowsHide: true }) and tell us if the window is still popping up. This would help us know if this is an issue with Node.js or Execa.
  2. Run the same code without electron (if that's possible). If this bug is Electron-related, this might be harder to reproduce and fix.

@rynz
Copy link
Author

rynz commented Jul 3, 2019

  1. Yes, a window is still popping up.
  2. Looks like it is a nodejs bug, this is the code I used to test on node v12.4.0
const path = require('path')
const { spawn } = require('child_process')

const run = (args) => {
  return new Promise((resolve) => {
    const cmd = path.resolve(__dirname, 'foo', 'bar.exe')
    const ls = spawn(cmd, args, { shell: true, detached: true, windowsHide: true })
    ls.on('close', () => {
      resolve()
    })
  })
}

run(['--test']).then(() => {
  console.log('Done')
})

Note: bar.exe runs with UAC, so a UAC prompt appears and after clicking "Yes" the cmd.exe window appears.

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

I think your code example might be reduced to:

const { spawn } = require('child_process')
spawn('./foo/bar.exe', ['--test'], { shell: true, detached: true, windowsHide: true })

Am I correct? Does this still create a window?

If I'm correct, please try to remove the shell and detached options as well, and see if the window is still popping up.

Note: this assumes the current directory is the parent directory of foo/.

@rynz
Copy link
Author

rynz commented Jul 3, 2019

const { spawn } = require('child_process')
spawn('.\\foo\\bar.exe', ['--test'], { shell: true, detached: true, windowsHide: true })

On Windows, yes window still popping up after UAC prompt.

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

Does it still pop up after you remove shell and/or detached?

@rynz
Copy link
Author

rynz commented Jul 3, 2019

Removing shell it no longer pops up, however, I have to run node test.js with cmd.exe as Administrator due to the UAC. If I run it without Administrator then I get EACCES due to UAC not being triggered by the new shell.

If I run as Administrator with shell: true then it still pops up even without UAC prompt.

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

To summarize (correct me if I got it wrong):

  • UAC appears if shell: false but not if shell: true
  • window pops up if shell: true but not if shell: false

What about detached? I'm assuming detached: false should not pop up a new window, I just want to confirm.

@rynz
Copy link
Author

rynz commented Jul 3, 2019

To summarise

  • run cmd.exe and execute node test.js with shell: true. UAC prompt appears, then new cmd.exe window pops up.
  • run cmd.exe "Run as administrator" and execute node test.js with shell: true. UAC prompt no longer appears, then new cmd.exe window pops up.
  • run cmd.exe and execute node test.js with shell: false. Throws an exception EACCES as it does not have privileges to execute bar.exe.
  • run cmd.exe "Run as administrator" and execute node test.js with shell: false. UAC prompt no longer appears and no new cmd.exe window pops up (expected behavior).
  • run cmd.exe and execute node test.js with shell: true, detached: false. UAC prompt appears, then new cmd.exe window pops up.
  • run cmd.exe "Run as administrator" and execute node test.js with shell: true, detached: false. UAC prompt no longer appears and no new cmd.exe window pops up (expected behavior).

Therefore, when detached: false the new cmd.exe window pops up only when UAC prompt appears prior.

@ehmicky
Copy link
Collaborator

ehmicky commented Jul 3, 2019

Could this be due to this Node bug?

@rynz
Copy link
Author

rynz commented Jul 3, 2019

Could this be due to this Node bug?

Yes, looks related cheers! I'll follow up there. Thanks for taking the time to help! 👍

@rynz rynz closed this as completed Jul 3, 2019
@ehmicky ehmicky changed the title hide shell windowsHide: true does not work when using shell: true and detached: true Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants