Created
July 5, 2019 22:38
-
-
Save nikhilm/34d156f58ea353ed3275b434dcaf5808 to your computer and use it in GitHub Desktop.
test case for https://github.com/softprops/atty/issues/34 - after building main.rs as a binary crate called testatty, run notty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "testatty" | |
version = "0.1.0" | |
authors = ["vagrant"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
atty = { path= "../atty"} | |
isatty = { path="../isatty"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//use atty; | |
use isatty; | |
fn main() { | |
//if atty::is(atty::Stream::Stdout) { | |
if isatty::stdout_isatty() { | |
println!("Yes TTY"); | |
} else { println!("NO TTY"); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import tempfile | |
# this makess isatty panic | |
path = '\\\\?\\C:\\' + os.path.join(*(['a'* 8]*12)) + ('a'*19 + '.txt') | |
# this would've made atty fail, but doesn't since it does correct offset calculations. | |
# path = '\\\\?\\C:\\' + os.path.join(*(['a'* 8]*26)) + ('a'*25 + '.txt') | |
print(len(path), path) | |
if not os.path.exists(os.path.dirname(path)): | |
os.makedirs(os.path.dirname(path)) | |
with open(path, 'w') as fp, tempfile.TemporaryFile('r') as stdin, tempfile.TemporaryFile() as stderr: | |
try: | |
print(subprocess.check_call(["target\\debug\\testatty.exe"], stdout=fp, stdin=stdin, stderr=stderr)) | |
except subprocess.CalledProcessError as e: | |
print(e) | |
stderr.seek(0) | |
print("STDERR", stderr.read()) | |
with open(path, 'r') as fp: | |
print(fp.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment