# 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:** 1\
**Showing post:** 8

<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)

🙂

---

_[View the full topic](https://discourse.processing.org/t/cant-detect-pde-vs-command-line-pde-no-longer-passing-external/10508)._
