# Can't detect PDE vs command line, PDE no longer passing --external

**URL:** <https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508>\
**Category:** Coding Questions\
**Created:** [April 20, 2019, 9:41pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508 "2019-04-20T21:41:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 20, 2019, 9:41pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/1 "2019-04-20T21:41:28Z")

</div>

Two years ago I developed a sketch that could be run from PDE or from the command line (`processing-java`) – optionally with arguments. I wanted the sketch to know which way it had been run (PDE or command line).

- [Detect command line invocation of a sketch? - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/23999/detect-command-line-invocation-of-a-sketch)

With help from @koogs, I developed a method, which worked in 3.4 and back but no longer works.

```auto
boolean PDE;
void setup() {
  String cmd = System.getProperty("sun.java.command");
  println(cmd);
  if (cmd.contains("--external")) {
    PDE=true;
  } else {
    PDE=false;
  }
  println(PDE);
}

```

That worked up to 3.4 – When run from PDE the output contains “–external” and the flag is set.

> processing.core.PApplet --location=1213,185 --external --display=1 --sketch-path=/Users/student/Downloads/Test Test

Now, in 3.5.3, that method isn’t working anymore. When run from PDE, the “external” flag is missing.

> processing.core.PApplet --display=1 --sketch-path=/Users/student/Downloads/Test Test

Any idea why / how this might have happened? Is it a bug / regression, or a change in Processing, or the bundled Java? I’m not even sure where to start looking.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 25, 2019, 6:34pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/2 "2019-08-25T18:34:12Z")

</div>

A (non) update: I have an issue open on this, but I have never managed to track down which commit changed this behavior, where in the source code. At some point may need to just remove this feature from the JavaDoc documentation if it can’t be fixed…

> <https://github.com/processing/processing/issues/5843>

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 25, 2019, 7:27pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/3 "2019-08-25T19:27:11Z")

</div>

I ran your sketch:

> [Detect command line invocation of a sketch? - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/23999/detect-command-line-invocation-of-a-sketch)

Command-line (Windows 10) output:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2d29ca2a38e1f37b2369872674c2accce9d10c50.png)

I did remove the exit() and added a draw() with a red background:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4a83aa1a8eb7d7049caaf2383ff72c90b1f184f1.png)

That is all I did to explore this…

🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 25, 2019, 7:29pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/4 "2019-08-25T19:29:15Z")

</div>

Thanks – what version of processing-java and Processing?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 25, 2019, 7:35pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/5 "2019-08-25T19:35:58Z")

</div>

I have a few versions of Processing installed so may not be using the version I expect from the command line:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2cf6e902ae1b4a628c010f58eeecea32512f01ab.png)

Processing 3.5.3 is what I use; others versions installed also.

Windows 10

I referenced this topic for the cd:

> [@Having trouble running pde file from command line](https://discourse.processing.org/t/having-trouble-running-pde-file-from-command-line/7344/2):
>
> hi, i can not help about the cygwin thing, still i think that you first should confirm that processing-java works. so when you say I’m in the correct directory. again, open a cmd window there? yourdrive:/…/processing-3.4/ check with dir that you see processing-java.exe (26.07.2018) and type processing-java --sketch=yourdrive:/../processing-3.4/modes/java/examples/Basics/Image/LoadDisplayImage --run it works here / win 7 / but full install processing 3.4 IDE

Update:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1e7c0b77d342918270367569f07a1d771dc26636.png)

🙂

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 25, 2019, 10:33pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/6 "2019-08-25T22:33:18Z")

</div>

This got me exploring…

A “workaround” may be to pass “external” (anything will work here) as an argument and check for that.

🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 26, 2019, 4:42am UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/7 "2019-08-26T04:42:44Z")

</div>

Thanks. 0269 is the latest, I believe.

Interesting workaround idea – should work. I’ll look at it with my toolchain.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 26, 2019, 10:56am UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/8 "2019-08-26T10:56:41Z")

</div>

Thanks for bringing this to the topics!  
I will be using processing command-line in the future.

This is my first pass at this and “green” background from command-line launch and “red” from PDE launch:

```auto
//https://forum.processing.org/two/discussion/23999/detect-command-line-invocation-of-a-sketch
// 2019-08-25
// Modified to check for external argument only!

/**
 * CommandLineDetect
 * 2017-09-21 Jeremy Douglass - Processing 3.3.6 
 * Was a sketch run from PDE, or from the command line?
 * If from the command line, what are its arguments and their values?
 * 
 * Invoke it:
 * 1. from the command line above the sketch folder, with no arguments:
 * processing-java --sketch=`pwd`/CommandLineDetect --run
 * 2. ...or with arguments:
 * processing-java --sketch=`pwd`/CommandLineDetect --run foo bar=baz lorem="ipsum dolor sit amet, consectetur adipiscing elit" etc 
 * 3. or form PDE
 *
 * The sketch relies on the --external flag to detect a PDE launch, as per:
 * - processing.github.io/processing-javadocs/core/processing/core/PApplet.html#main-java.lang.String:A-
 * 
 * The command line passes in a String[] of args. If you wish to arguments of the:
 * - form foo=bar
 * - lorem="ipsum dolor"
 * 
 * Related forum discussions:
 * - forum.processing.org/two/discussion/23999/detect-command-line-invocation-of-a-sketch
 * - forum.processing.org/two/discussion/23924/handling-command-line-arguments-in-a-sketch
 * - forum.processing.org/two/discussion/6457/how-to-use-arguments-with-an-application-built-with-processing
 */
 
// Some editing by GLV. See original (above) for the complete version.

boolean PDE;
StringDict argDict = new StringDict();
color setBack = 0;
String str1;

void setup() 
  {

// Local command-line arguments for testing:  
// String [] args = {"external", "foo", "bar=baz", "lorem=ipsum dolor sit amet, consectetur adipiscing elit", "etc"};
  
  println(args == null ? "null" : args);
  if (args == null) 
    str1 = "internal";
  else
    str1 = args[0];
  
  if (str1.equals("external")) 
    {
    PDE=true;
    setBack = color(0, 255, 0);
    } 
  else 
    {
    PDE=false;
    setBack = color(255, 0, 0);
    }
 
  // load command line arguments, load them
  if (args != null) 
    {
    for (String arg : args) 
      {
      String[] entry = split(arg, "=");
      if (entry.length == 1) 
        {
        argDict.set(entry[0], "");
        }
      if (entry.length == 2) 
        {
        argDict.set(entry[0], entry[1]);
        }
      }
    }
 
  // set default if specific arg not present
  if (!argDict.hasKey("xyzzy")) {
    println("Setting default for xyzzy");
    // ...do something
  }
 
  // demonstrate using arguments
  for (String arg : argDict.keyArray()) {
    switch(arg) {
      
    case "external":
      //arg external
      println("mode:", arg);
      break;
    //case "foo":
    // // key only arg
    // println("mode:", arg);
    // // ...do something
    // break;
    case "bar":
      // key=value arg
      println("Setting", arg, "=", argDict.get(arg));
      // ...do something
      break;
    case "lorem":
      // parsed value
      String parsed = join(sort(argDict.get(arg).split(" ")), " ");
      println("Sorting", arg, "=", parsed);
      // ...do something
      break;
    }
  }
  //exit();
}

void draw()
  {
  background(setBack);  
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f17fb5cfb240b4fdbd71683ac54f07afe022fab7.png)

🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 26, 2019, 4:50pm UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/9 "2019-08-26T16:50:43Z")

</div>

Really glad that this is helpful and useful to you. Looking forward to what you do with it.

When I developed this it was for Edger, a Processing sketch that could be invoked in two ways –

1. from PDE, where it created a user interface for researchers to processing sparse edglist files into network graphs
2. from the command line, so a Jekyll static site generator could batch process hundreds of network graphs for a website without launching the graphical interface.

Because the command line was invoking a batch-process mode, I wanted to the PDE version to launch-and-wait (for user input), and the command line version to launch-and-run (with optional command-line arguments). That was the original use case for detecting “how was I launched?” When it could be done automatically, that was elegant. But you are right – explicitly passing it a flag “external” (or perhaps “batch” in my use-case) is a solid workaround.

---

<div class="post-metadata">

**Author:** ![Brahvim](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/brahvim/32/14756_2.png) [@Brahvim](https://discourse.processing.org/u/Brahvim)\
**Post date:** [August 26, 2022, 11:49am UTC](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508/10 "2022-08-26T11:49:54Z")

</div>

Hello!

Just a few minutes ago, I discovered that `System.getProperty("sun.java.command").split(" ")` returns an array of length **one** , where the first argument is the sketch class’s name. Only the PDE adds the `--display` and the `--sketch-path` flags in. This is perhaps a helpful discovery, since one can now simply check if the other two arguments `.contain()` those exact flags. We could also add an extra argument for when the sketch runs outside the PDE, and run it only with that argument outside the PDE.

- **Processing `3.5.4`.**
