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

Uncaught Error: EPERM: operation not permitted, write #2033

Closed
kirkouimet opened this issue Jun 22, 2015 · 10 comments
Closed

Uncaught Error: EPERM: operation not permitted, write #2033

kirkouimet opened this issue Jun 22, 2015 · 10 comments

Comments

@kirkouimet
Copy link
Contributor

I'm getting this error in Windows 8.1 when I run my app using the .exe:

image

When I run my app from the command line it works with no problem.

Any ideas on what could be causing the permissions issue or the best way on how I can debug it further?

@zcbenz
Copy link
Member

zcbenz commented Jun 23, 2015

You can set the devtools to catch uncaught exceptions and see the stack trace there.
screen shot 2015-06-23 at 11 07 40 am

@zcbenz zcbenz closed this as completed Jun 23, 2015
@kirkouimet
Copy link
Contributor Author

@zcbenz thank you! So here is what I discovered using dev tools:

In Windows 8.1, this is my code causing the problem:

process.stdout.write('hi')

[Good] When I run electron from the command line, this code works without a problem and I see 'hi' in my command prompt.

[Bad] When I run a packaged version of my app by running the .exe I get this error:

Uncaught Error: EPERM: operation not permitted, write

I think this makes sense because there is no stdout to write to since there is no attached command prompt?

I inspected the process.stdout property to see if it had any properties I could use to conditionally call process.stdout based on whether or not there is a command prompt present. I couldn't find anything as process.stdout shows as being writable with no command prompt even though it throws the EPERM exception:

image

Any ideas on how I could go about solving this one? Would love to use this as a learning opportunity for me as well as to help improve Electron.

Thanks!

@zcbenz
Copy link
Member

zcbenz commented Jun 24, 2015

That's because on Windows a GUI program does not have console attached when it is not opened in console, which means you actually don't have stdout. So writing to stdout under this situation will throw the exception.

@kirkouimetsnapchat
Copy link

@zcbenz is there anyway for me to programmatically detect whether or not there is a console attached?

@zcbenz
Copy link
Member

zcbenz commented Jun 24, 2015

There should be some win32 API for this, but I think the best solution is to use console.log for logging, writing to stdout is quite tricky on Windows.

@kirkouimet
Copy link
Contributor Author

My solution is pretty bad, but will do this for now until I learn more about win32 APIs for detecting if stdout is available to write to.

try {
    stdout.write(string);
}
catch(exception) {
    console.log(string);
}

@ang3lx
Copy link

ang3lx commented Jan 25, 2016

@kirkouimet i've this problem with sql.js that use stdout.
how can fix with your solution?

@kirkouimet
Copy link
Contributor Author

@ang3lx I think you are screwed unless you can somehow configure sql.js to use console.log instead of stdout.write. That is unless @zcbenz has any new ideas since we last talked

@jimbuck
Copy link

jimbuck commented Mar 1, 2016

I had this issue with the Console transport for Winston. The workaround was quite simple, don't enable the stdout transport when in production!

@jayralencar
Copy link

Hi, I solved it like this:
process.stderr.write = console.error.bind(console); process.stdout.write = console.log.bind(console); //before requiring sql.js var SQL = require('sql.js');

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

6 participants