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

stdout cannot be reassigned on some systems #12939

Closed
genotrance opened this issue Dec 20, 2019 · 3 comments
Closed

stdout cannot be reassigned on some systems #12939

genotrance opened this issue Dec 20, 2019 · 3 comments

Comments

@genotrance
Copy link
Contributor

@genotrance genotrance commented Dec 20, 2019

Consider:

var f: File
  
stdout = f

On Ubuntu and OSX, this works fine. In my code, I am backing up stdout and restoring it later.

However, on Windows I see:

error: lvalue required as left operand of assignment
  stdout = f__diPCTL71W7KGJSC9aB9avGTw;

On the Nim playground, I see:

error: assignment of read-only variable 'stdout'
  stdout = f_aaZ4Cbdkmq1Yxbybfr175A;

stdout is a var so it should be writable in theory.

@Araq

This comment has been minimized.

Copy link
Member

@Araq Araq commented Dec 23, 2019

Use system.reopen instead.

@Araq Araq closed this Dec 23, 2019
@genotrance

This comment has been minimized.

Copy link
Contributor Author

@genotrance genotrance commented Dec 23, 2019

I am using reopen for Windows but cannot recover stdout when I want it back later on in my program.

https://github.com/nimterop/nimterop/blob/master/nimterop/toast.nim#L171

Any reason why this shouldn't work consistently across OS?

@genotrance

This comment has been minimized.

Copy link
Contributor Author

@genotrance genotrance commented Jan 14, 2020

stdout cannot be reassigned on some systems. glibc is okay with it but it fails on Windows and musl based systems. This isn't a Nim issue.

https://stackoverflow.com/questions/1908687/how-to-redirect-the-output-back-to-the-screen-after-freopenout-txt-a-stdo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.