Last active
August 29, 2015 14:16
-
-
Save lmmx/9bdec10b4307d640fade to your computer and use it in GitHub Desktop.
Example JSON for replicating SIGPIPE error when piping from an Rscript - http://stackoverflow.com/q/28915838/2668831
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
{"id":"abcdefg","title":"Example note 1","content":"Lorem ipsum.","taskAll":0,"taskCompleted":0,"created":0000000000000,"updated":1111111111111,"notebookId":0,"tags":[],"isFavorite":0,"trash":0,"synchronized":0,"images":[],"redirect":true} |
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
{"id":"hijklmn","title":"Example note 2","content":"Dolor sit amet.","taskAll":0,"taskCompleted":0,"created":0000000000000,"updated":1111111111111,"notebookId":0,"tags":[],"isFavorite":0,"trash":0,"synchronized":0,"images":[],"redirect":true} |
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
#!/usr/bin/env Rscript | |
#library('RJSONIO') | |
note.list <- c('abcdefg.json', | |
'hijklmn.json') | |
for (laverna.note in note.list) { | |
# note.file <- path.expand(file.path('~/Dropbox/Apps/Laverna/notes',laverna.note)) | |
# For the purpose of this example run the script in the same directory as the JSON files | |
note.file <- path.expand(file.path(getwd(),laverna.note)) | |
file.conn <- file(note.file) | |
suppressWarnings( | |
# cat(paste0(fromJSON(file.conn)$content),'\n') | |
cat(paste0(substr(readLines(file.conn), 2, 15)),'\n') | |
) | |
# close(file.conn) | |
} | |
# Rscript myscript.R | |
# ==> | |
# "id":"abcdefg" | |
# "id":"hijklmn" | |
# Rscript myscript.R | head -2 | |
# ==> | |
# "id":"abcdefg" | |
# "id":"hijklmn" | |
# Error: ignoring SIGPIPE signal | |
# Execution halted | |
# Rscript myscript.R | head -1 | |
# ==> | |
# "id":"abcdefg" | |
# Error: ignoring SIGPIPE signal | |
# Execution halted | |
# closing all connections at the end with | |
# closeAllConnections() | |
# does not affect the race condition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment