Skip to content

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

Description

@noncreature0714

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.

Activity

  1. addaleax commented on Jan 5, 2017

    @addaleax
    Member

    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 :)

  2. noncreature0714 commented on Jan 5, 2017

    @noncreature0714
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions