From 9baf94948afefa869a707d30330fb9d29e227d7e Mon Sep 17 00:00:00 2001 From: Pekka Ristola Date: Wed, 29 Dec 2021 14:18:54 +0200 Subject: [PATCH 1/2] Use "C" locale for system ping command on Linux Fixes `pingr::ping()` when system has non-english locale by default --- R/ping-package.r | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/ping-package.r b/R/ping-package.r index a62b181..34eec24 100644 --- a/R/ping-package.r +++ b/R/ping-package.r @@ -67,7 +67,7 @@ ping <- function(destination, continuous = FALSE, verbose = continuous, os <- ping_os(destination, continuous, count, timeout) - status <- run(os$cmd[1], os$cmd[-1], error_on_status = FALSE) + status <- run(os$cmd[1], os$cmd[-1], error_on_status = FALSE, env = os$env) output <- strsplit(status$stdout, "\r?\n")[[1]] if (!continuous) { @@ -83,6 +83,8 @@ ping <- function(destination, continuous = FALSE, verbose = continuous, ping_os <- function(destination, continuous, count, timeout) { + env <- NULL + if (.Platform$OS.type == "windows") { ping_file <- file.path("C:", "windows", "system32", "ping.exe") if (!file.exists(ping_file)) { ping_file <- "ping" } @@ -108,6 +110,7 @@ ping_os <- function(destination, continuous, count, timeout) { if (!continuous) c("-c", count), destination ) + env <- c("current", LC_ALL = "C") } else if (Sys.info()[["sysname"]] == "SunOS") { if (timeout != 1.0) { @@ -129,7 +132,7 @@ ping_os <- function(destination, continuous, count, timeout) { ) } - list(cmd = cmd, regex = "^.*time=(.+)[ ]?ms.*$") + list(cmd = cmd, env = env, regex = "^.*time=(.+)[ ]?ms.*$") } #' Is the computer online? From fb9223a319437352d65f2dc634f8359834e75038 Mon Sep 17 00:00:00 2001 From: Pekka Ristola Date: Wed, 29 Dec 2021 17:30:15 +0200 Subject: [PATCH 2/2] Update NEWS.md --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 2478178..ba4ec73 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,9 @@ * `is_online()` now tries the Apple captive test first, because it works better when DNS is not masked, but HTTP is (#13). +* `ping()` now works on Linux systems with a non-English locale + [@pekkarr](https://github.com/pekkarr) (#18). + # 2.0.0 * New `nsl()` function to perform DNS queries.