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

readFileSync Appears Un-synchronous or Fails on Raspberry Pi 3 #10621

Closed
noncreature0714 opened this issue Jan 5, 2017 · 2 comments
Closed
Labels
question Issues that look for answers.

Comments

@noncreature0714
Copy link

noncreature0714 commented Jan 5, 2017

Situation:

I'm trying to capture my RPi3's mac addresses using synchronous file reading, getting information from my host system at `/sys/class/net/*/address`.

Action:

I have two branches at this repo: https://github.com/noncreature0714/gen-sys-id-node.git

Branch master is the asynchronous version, and works successfully.
Branch sync-test is synchronous, and is not working as expected - almost as if it never ran synchronously.

Results:

Output of 'master' (asynchronous) branch is:

ifs.eth0: "my correct eth0 mac address here"
ifs.wlan0: "my correct wlan0 mac address here"

Output of 'sync-test' branch is:

ifs.eth0: function String() { [native code]}
ifs.wlan0: function String() { [native code]}

Summary

The values where never assigned, almost like what happens when asynchronous operations occur after accessing variables. Additionally, the `console.log()` inside the functions never logs. Which leads me to consider the possibility that `readFileSync` may not be working at all.
@addaleax addaleax added the question Issues that look for answers. label Jan 5, 2017
@addaleax
Copy link
Member

addaleax commented Jan 5, 2017

You can’t use fs.readFileSync with callbacks, it just gives you the file contents as the return value. You’ll have to write something like this:

ifs.eth0 = fs.readFileSync('/sys/class/net/eth0/address');

etc.

I’ll be closing this as it’s very likely not an issue with node core, but if you have any trouble getting this to work, please open an issue at https://github.com/nodejs/help :)

@addaleax addaleax closed this as completed Jan 5, 2017
@noncreature0714
Copy link
Author

@addaleax I think Homer Simpson has a word for this... But thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants