Questions tagged [dev-null]

On Unix-like systems, /dev/null is a device file that discards all data written to it but reports that the write operation succeeded.

On Unix-like systems, /dev/null is a device file that discards all data written to it but reports that the write operation succeeded. It is typically used for disposing of unwanted output streams of a process, or as a convenient empty file for input streams.

69 questions
3
votes
2 answers

How to write to a NULL device/file on Windows (10) so I can **not** read back what was written?

Windows does have a concept for null devices as detailed here, here or here for example. All examples that I can find are about redirecting streams. While porting a script from Linux to Windows, I came across something odd: If nul is opened like a…
s-m-e
  • 3,433
  • 2
  • 34
  • 71
3
votes
1 answer

Golang - Discard as WriteCloser

I needed to create an equivalent of ioutil.Discard that can satisfy a "WriteCloser" interface. With a bit of Googling I came up with package main import ( "io" "io/ioutil" "strings" "fmt" ) type discardCloser struct { …
tuck1s
  • 1,002
  • 9
  • 28
3
votes
2 answers

Omit error from shell script output

I'd like to omit the error from this IF statement if ICMP echo fails. Example code: if ping -q -c 1 -W 1 1.2.3.4 >/dev/null; then echo -e "PING OK" else echo -e "PING NOK" fi It works perfectly if the ping is successful or you run the command…
Liam Mulligan
  • 35
  • 1
  • 5
3
votes
1 answer

Platform-independent way to discard out/err with ProcessBuilder

On Unix you can discard a process' output with: pb.redirectOutput(new File("/dev/null")); While on Windows you instead need to use NUL. Is there a better option than the following snippet for supporting arbitrary platforms? File devNull = new…
dimo414
  • 47,227
  • 18
  • 148
  • 244
3
votes
1 answer

linux : close or redirect standard output to /dev/null after detaching from terminal

We have a linux code that does detaching from terminal based on implementation found on http://www.itp.uzh.ch/~dpotter/howto/daemonize. Here a code snippet from it : .... freopen( "/dev/null", "r", stdin); freopen( "/dev/null", "w",…
drus
  • 495
  • 2
  • 6
  • 13
3
votes
4 answers

Bash: redirect to screen or /dev/null depending on flag

I'm trying to come up with a way script to pass a silent flag in a bash so that all output will be directed to /dev/null if it is present and to the screen if it is not. An MWE of my script would be: #!/bin/bash # Check if silent flag is on. if…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
3
votes
2 answers

Download file to null (Windows CLI)

I would like to download a file to null in windows cli just for testing purposes. In linux i used wget http://download.thinkbroadband.com/1GB.zip -O /dev/null This kept my connection busy for a while. Is there any way to do this in command prompt…
RokX
  • 334
  • 6
  • 16
3
votes
2 answers

Equivalent of /dev/null for writing garbage test data?

I need to perform a series of test for picking the fastest branch of code for a set of functions I designed. As this functions output some text/HTML content, I would like to measure the speed without filling the browser with garbage data. Is there…
Julio María Meca Hansen
  • 1,303
  • 1
  • 17
  • 37
2
votes
1 answer

How to output data to file but also suppress output on the terminal?

I'm trying to execute a system command in python but I am using > /dev/null 2>&1 to hide all the output. I'm trying to just display very specific output, but I am also trying to output the data to a file > grep.txt so that I can grep the specific…
theshape
  • 11
  • 7
2
votes
0 answers

pathlib's Path("NUL:").resolve() throws an error on windows. Is this a bug?

I'm looking for the equivalent windows functionality to the posix /dev/null file, and I discovered NUL: This snippet works on a windows OS, proving that it is indeed a writable file: Path('NUL:').write_text('abcd') However, Path('NUL:').resolve()…
Phillmac
  • 109
  • 7
2
votes
1 answer

Redirecting or appending to /dev/null

>/dev/null or >>/dev/null? I understand the difference when writing (to) a regular file. But when it comes to /dev/null? Comments? Advices?
useful
  • 147
  • 5
2
votes
1 answer

Special handling of /dev/null in open and write?

according to a hint from another thread I want to analyze pointers, if their dereferencing would cause an segmentation faults or not. The idea is to write code like this: bool IsPointerValid( void* pPointer ) { // when opening "/tmp/hugo" here,…
Charly
  • 1,270
  • 19
  • 42
2
votes
1 answer

/dev/null No such file or directory

I run El Capitan OS X and am trying to use /dev/null however when I do anything with it, for example ls: ls -l /dev/null ls: /dev/null: No such file or directory I've also tried: sudo mknod -m 666 /dev/null c 1 3 However that outputs the…
CertifcateJunky
  • 161
  • 1
  • 11
2
votes
1 answer

How does > /dev/null eat up output streams?

I've used /dev/null a lot in bash programming to send unnecessary output into a black hole. For example, this command: $ echo 'foo bar' > /dev/null $ Will not echo anything. I've read that /dev/null is an empty file used to dispose of unwanted…
cs95
  • 379,657
  • 97
  • 704
  • 746
2
votes
1 answer

What's the significance of specifying a file mode when reopening STDOUT to /dev/null?

I'm reading an example ruby script that creates a daemon by forking, creating a new session, forking again, then redirecting stdin, stdout, stderr to /dev/null Here's a snippet of the redirection: STDIN.reopen '/dev/null' STDOUT.reopen '/dev/null',…
ivan
  • 6,032
  • 9
  • 42
  • 65