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

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
Copy link
Member

Araq commented Dec 23, 2019

Use system.reopen instead.

@Araq Araq closed this as completed Dec 23, 2019
@genotrance
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants