Changeset 9738db7 for core/java


Ignore:
Timestamp:
Dec 12, 2018 8:12:07 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6c3c227c
Parents:
51bf23a
Message:

UrlLauncher?:

  • Use arrays for exec
  • Randomize temp file name
  • Require quotes around args containing spaces in routerconsole.browser property
  • Add debug logging
  • Add chromium-browser to the default list
  • Parse and use full command line from Windows registry
  • Replace %1 with url in registry line and routerconsole.browser property

ShellCommand?:

  • Switch to i2p logging
File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/ShellCommand.java

    r51bf23a r9738db7  
    1818import java.io.OutputStreamWriter;
    1919import java.util.Arrays;
     20
     21import net.i2p.I2PAppContext;
    2022
    2123/**
     
    2931public class ShellCommand {
    3032
    31     private static final boolean DEBUG = false;
    3233    private static final boolean CONSUME_OUTPUT    = true;
    3334    private static final boolean NO_CONSUME_OUTPUT = false;
     
    359360        String name = null;
    360361        long begin = 0;
    361         if (DEBUG) {
     362        Log log = I2PAppContext.getGlobalContext().logManager().getLog(ShellCommand.class);
     363        if (log.shouldDebug()) {
    362364            if (shellCommand instanceof String) {
    363365                name = (String) shellCommand;
     
    375377                commandThread.join(seconds * 1000);
    376378                if (commandThread.isAlive()) {
    377                     if (DEBUG)
    378                         System.out.println("ShellCommand gave up waiting for \"" + name + "\" after " + seconds + " seconds");
     379                    if (log.shouldDebug())
     380                        log.debug("ShellCommand gave up waiting for \"" + name + "\" after " + seconds + " seconds");
    379381                    return true;
    380382                }
     
    383385            // Wake up, time to die.
    384386        }
    385         if (DEBUG)
    386             System.out.println("ShellCommand returning " + result.commandSuccessful + " for \"" + name + "\" after " + (System.currentTimeMillis() - begin) + " ms");
     387        if (log.shouldDebug())
     388            log.debug("ShellCommand returning " + result.commandSuccessful + " for \"" + name + "\" after " + (System.currentTimeMillis() - begin) + " ms");
    387389        return result.commandSuccessful;
    388390    }
     
    427429        Process process;
    428430        String name = null;  // for debugging only
     431        Log log = I2PAppContext.getGlobalContext().logManager().getLog(ShellCommand.class);
    429432        try {
    430433            // easy way so we don't have to copy this whole method
    431434            if (shellCommand instanceof String) {
    432435                name = (String) shellCommand;
    433                 if (DEBUG)
    434                     System.out.println("ShellCommand exec \"" + name + "\" consume? " + consumeOutput + " wait? " + waitForExitStatus);
     436                if (log.shouldDebug())
     437                    log.debug("ShellCommand exec \"" + name + "\" consume? " + consumeOutput + " wait? " + waitForExitStatus);
    435438                process = Runtime.getRuntime().exec(name);
    436439            } else if (shellCommand instanceof String[]) {
    437440                String[] arr = (String[]) shellCommand;
    438                 if (DEBUG) {
     441                if (log.shouldDebug()) {
    439442                    name = Arrays.toString(arr);
    440                     System.out.println("ShellCommand exec \"" + name + "\" consume? " + consumeOutput + " wait? " + waitForExitStatus);
     443                    log.debug("ShellCommand exec \"" + name + "\" consume? " + consumeOutput + " wait? " + waitForExitStatus);
    441444                }
    442445                process = Runtime.getRuntime().exec(arr);
     
    462465            }
    463466            if (waitForExitStatus) {
    464                 if (DEBUG)
    465                     System.out.println("ShellCommand waiting for \"" + name + '\"');
     467                if (log.shouldDebug())
     468                    log.debug("ShellCommand waiting for \"" + name + '\"');
    466469                try {
    467470                    process.waitFor();
    468471                } catch (InterruptedException e) {
    469                     if (DEBUG) {
    470                         System.out.println("ShellCommand exception waiting for \"" + name + '\"');
    471                         e.printStackTrace();
     472                    if (log.shouldWarn()) {
     473                        log.warn("ShellCommand exception waiting for \"" + name + '"', e);
    472474                    }
    473475                    if (!consumeOutput)
     
    479481                    killStreams();
    480482
    481                 if (DEBUG)
    482                     System.out.println("ShellCommand exit value is " + process.exitValue() + " for \"" + name + '\"');
     483                if (log.shouldDebug())
     484                    log.debug("ShellCommand exit value is " + process.exitValue() + " for \"" + name + '\"');
    483485                if (process.exitValue() > 0)
    484486                    return false;
     
    486488        } catch (IOException e) {
    487489            // probably IOException, file not found from exec()
    488             if (DEBUG) {
    489                 System.out.println("ShellCommand execute exception for \"" + name + '\"');
    490                 e.printStackTrace();
     490            if (log.shouldWarn()) {
     491                log.warn("ShellCommand execute exception for \"" + name + '"', e);
    491492            }
    492493            return false;
Note: See TracChangeset for help on using the changeset viewer.