m4rc3l05
m4rc3l05
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
it is only a file if you do input redirection < deno.json
20 replies
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
using this simple deno script that uses the deprecated methods/properties:
#!/usr/bin/env deno

console.log("isFile => ", Deno.fstatSync(Deno.stdin.rid).isFile);
#!/usr/bin/env deno

console.log("isFile => ", Deno.fstatSync(Deno.stdin.rid).isFile);
Here what i have:
./foo.ts
isFile => false
./foo.ts
isFile => false
echo "foo" | ./foo.ts
isFile => false
echo "foo" | ./foo.ts
isFile => false
./foo.ts < deno.json
isFile => true
./foo.ts < deno.json
isFile => true
20 replies
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
Decided to use nodejs apis for this. thx everybody for you suggestions.
20 replies
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
The idea would be to have what pino-pretty does but with deno apis, but then i noticed this issue with the deprecations and started to wonder how would i do it without nodejs apis for deno v2. So currently not possible then?
20 replies
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
stdin.isTerminal() does not seem to be what i want, given the example from pino-pretty https://github.com/pinojs/pino-pretty/blob/master/bin.js#L86, they check if stdin is terminal and if stdin is a file and if both are false it means that we are piping to the script and we should do nothing on the first sigint and exit on the next one, allowing to wait for the process being piped to close before closing it self, as explained in https://github.com/pinojs/pino/pull/358#issuecomment-366185875 the stdin.isTerminal() answares the 2 point, but the 1 remain still remains, how do we check it in deno v2 without using deprecated methos? currently i am doing !Deno.stdin.isTerminal() && !Deno.fstatSync(Deno.stdin.rid).isFile bu this will not work for v2 right?
20 replies
DDeno
Created by m4rc3l05 on 9/21/2024 in #help
How to check if stdin is a file?
Hey, thx for the response, just tried but it only works if the contents of stdin is a filepath and it will not work for example if i execute the ts file like ./foo.js < deno.json for example.
20 replies