# Input Data from Command Line

**URL:** <https://discourse.processing.org/t/input-data-from-command-line/12344>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 27, 2019, 3:24pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344 "2019-06-27T15:24:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlerner](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dlerner](https://discourse.processing.org/u/dlerner)\
**Post date:** [June 27, 2019, 3:24pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/1 "2019-06-27T15:24:39Z")

</div>

I am trying to create a system to test motors and propellers and include a nice GUI using Processing. I am using an Arduino to measure some data but am also using certain other measurement tools that need to be plugged directly into the computer. Is it possible for Processing to read serial data from the Arduino as well as the computer’s command lines? I’m still relatively new to Processing so I’m not sure how to stream in data from anything other than the Arduino.

---

<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:** [June 27, 2019, 4:37pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/2 "2019-06-27T16:37:58Z")

</div>

I did not need to list this but did anyway!

It all started here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

I have had success with these individually and in combination to create some very cool projects:

1. Serial communications  
[Electronics / Processing.org](https://processing.org/tutorials/electronics/)

- Processing to\from Ardunio
- Processing to\from Processing
- Processing to applications that use serial communications
- Processing to any hardware that has serial communications

1. Network Client to Server  
[Network / Processing.org](https://processing.org/tutorials/network/)

2. Data from Network and PC  
[https://processing.org/tutorials/data/](https://processing.org/tutorials/data/)  
XML, JSON, tables, text files, etc.

3. Sound  
[Sound / Processing.org](https://processing.org/tutorials/sound/)

4. Interactivity:  
[Interactivity / Processing.org](https://processing.org/tutorials/interactivity/)

- keyboard, mouse and check out tools and libraries!

1. Print  
[Print / Processing.org](https://processing.org/tutorials/print/)

2. GUI interface to run a command-line tool  
I used some JAVA directly for this in the Processing applications.  
It was to control my LCD screen colors; I created an interface to a free command-line tool that did this.

3. Video  
[Video / Processing.org](https://processing.org/tutorials/video/)

4. And… check out the tools and libraries in the Processing software!

5. And… there are other modes like Android mode!  
Ketai libraries:  
[http://ketai.org/](http://ketai.org/)

I mostly just tinker with it as a hobby and posted some videos here:

> **[GLV](https://www.youtube.com/user/etshopstuff/featured)**
>
> Stuff. :)

🙂

---

<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:** [June 27, 2019, 5:06pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/3 "2019-06-27T17:06:50Z")

</div>

This is a few years old but still works with W10

This is a version 0.1 of mouse buttons sending command-line arguments to an app (app not included here):

```auto
import java.io.*;
String str1 = "3000";
int num = 1000;
boolean inc = false;
int num2 = 100;
boolean inc2 = false;

void settings()
  {
  size(200, 150, P2D);
  }
  
void draw()
  { 
  background(0);
  fill(255, 255, 0);
  textAlign(CENTER, CENTER);
  textSize(36);
  text(num, 100, 50);
  text(num2, 100, 100); 
  }
  
void mousePressed()
  {

  if (mouseButton == LEFT)
    {
    if (inc)
     num+=100;
    else
     num-=100;    
    
    if (num > 6500)
      {
      inc = false;
      num = 6500;
      }
    
    if (num < 1000)
      { 
      inc = true;
      num = 1000;
      }
  }  

  if (mouseButton == RIGHT)
    {
    if (inc2)
     num2+=5;
    else
     num2-=5;    
    
    if (num2 > 100)
      {
      inc2 = false;
      num2 = 100;
      }
    
    if (num2 < 20)
      { 
      inc2 = true;
      num2 = 20;
      }
  }  

  launch("C:\\app\\app.exe", Integer.toString(num), Integer.toString(num2));
  println(num, " ", num, " ", num2);
  }

```

---

<div class="post-metadata">

**Author:** ![dlerner](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dlerner](https://discourse.processing.org/u/dlerner)\
**Post date:** [June 27, 2019, 5:30pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/4 "2019-06-27T17:30:08Z")

</div>

Thank you so much for all of your help!  
Where is this program streaming data from the command line though?

---

<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:** [June 27, 2019, 6:17pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/5 "2019-06-27T18:17:32Z")

</div>

All I was doing at the time was launching and passing arguments to the app.exe.

This will require more exploration on your part.

[https://processing.org/reference/launch\_.html](https://processing.org/reference/launch_.html)

🙂

---

<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:** [June 27, 2019, 7:19pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/6 "2019-06-27T19:19:33Z")

</div>

I am able to launch cmd.exe and pass arguments with below:

> **[Java Program to open the command prompt and insert commands - GeeksforGeeks](https://www.geeksforgeeks.org/java-program-open-command-prompt-insert-commands/)**
>
> This article aims to provide you a simple code to open Command Prompt and how you can insert the commands in it using Java language.… Read More »

Examples tested:

```auto
exec(new String[] {"cmd", "/K", "start", "cmd.exe", "/K","help"});
exec(new String[] {"cmd", "/K", "start", "cmd.exe", "/K","ping 127.0.0.1"});

```

🙂

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 28, 2019, 10:03am UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/7 "2019-06-28T10:03:31Z")

</div>

> [@dlerner](#):
>
> Is it possible for Processing to read serial data from the computer’s command lines?

Not entirely clear what you want to achieve.

A command line: do you mean the user can type commands into your sketch?

Or is another program running (in DOS?) that sends out data? How does it send them?

---

<div class="post-metadata">

**Author:** ![dlerner](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dlerner](https://discourse.processing.org/u/dlerner)\
**Post date:** [June 28, 2019, 1:20pm UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/8 "2019-06-28T13:20:22Z")

</div>

I have something like 30 Amps of current running through my system so I have a powerful ammeter to track the current. The Ammeter connects to the [National Instruments USB-6210](https://www.ni.com/en-us/support/model.usb-6210.html) which has its own C-based library to send the readings into the computer. I am trying to make a Processing GUI for these readings as well as other readings coming from an Arduino. I know how to load serial data from an Arduino but I haven’t yet figured out how to get the data from the C++ program into Processing.

---

<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:** [July 3, 2019, 4:52am UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/9 "2019-07-03T04:52:22Z")

</div>

> [@dlerner](#):
>
> send the readings into the computer

It isn’t clear what you mean by this. It seems like you have some other program that is receiving the data. Via Serial? USB or network cable? Maybe USB? If you have a library for getting values from the USB device using another language, you could rebroadcast that information on a local protocol, e.g osc etc – there are lots of io and networking libraries for Processing.

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 3, 2019, 5:30am UTC](https://discourse.processing.org/t/input-data-from-command-line/12344/10 "2019-07-03T05:30:02Z")

</div>

It is possible in theory but there would be some research to be done unless you can find some resource out there that is doing this for you already. I am sure there are some people that have come up with libraries to access data from other languages like C or C++. In other words, possibly not an out-of-the-box solution. You do not need to focus your search limited to Processing. You could search any java module and it is very likely you can use this in Processing as it is Java after all.

You mentioned you want to get the data from the command prompt. From what I understand, you already have a program that read your NI module, correct? You can inquire this DAQ module using your command line command. As you have reported, you could use `exec()` to run this command and possible read the returned value returned after executing the command (This needs to be tested…). Is this enough for your case?

If the data is arriving via serial, you can try using RealTerm to see if you can capture the serial stream. If you are able to do this, then you should try the serial library in Processing and read the data stream directly. Keep in mind that if you are using an arduino, you might need to test working with two serial connections. I believe this is possible…

Kf
