sindresorhus / open

Open stuff like URLs, files, executables. Cross-platform.
MIT License
3.19k stars 220 forks source link

How do you close a program once you've opened it? #152

Open doverradio opened 5 years ago

doverradio commented 5 years ago

Hello, I was able to successfully open up a program using your library in Windows 10. Here is the code:

const open = require('open');

// Opens the program WordPerfect in the default image viewer
(async () => {
    await open('C:\\Program Files (x86)\\Corel\\WordPerfect Office X4\\Programs\\wpwin14.exe', {wait: true});
    console.log('Did WordPerfect open?');

})();

However, it's not clear how to close this once I've completed the tasks I need within that opened program.

How do I close this after I've completed using the opened program?

hong4rc commented 4 years ago

open give you a sub process, you can call it to kill itself. Unfortunately, that sub process create another process, which should be killed.

@sindresorhus Do you think that it is possible to resolve with sub process of start command(on window)?

ryanesch commented 4 years ago

@Hongarc can you give an example?

hong4rc commented 4 years ago

The main process create a new process (A)

A process creates another process(B, the application you want here)

You can close A process but I don't know how to close B process (you can add argument for B process but to get it)

einarpersson commented 4 years ago

Any ideas? Facing the same issue here

wgottschalk commented 4 years ago

also curious about this. I would love to open a chrome tab and then close it when my program (static file server) exits.

ZzqiZQute commented 4 years ago

Is there any solution? Got stuck here too!

Lunchb0ne commented 4 years ago

Yeap, same problem here!

EDIT: So I tried calling kill on the item it returns, via tree-kill, but still doesn't work