Skip to content

Commit

Permalink
Merge pull request #18 from pekkarr/ping-locale-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Dec 29, 2021
2 parents e7cdc4f + fb9223a commit bfe03f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions R/ping-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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" }
Expand All @@ -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) {
Expand All @@ -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?
Expand Down

0 comments on commit bfe03f4

Please sign in to comment.