NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO CloudSync for GCP
  • NEQTO Engine Firmware List
  • Support Guidelines

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. Utils
    • 14. nqLinux
    • 15. nqService
    • 16. nqMqtt
    • 17. nqFOTA
    • 18. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • SAP Cloud Platform Internet of Things
  • Splunk
  • Niagara

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases

12. SubProcess

The subprocess object is a built-in object that provides process communication functions between external applications using pipes.

Functional overview:

  • Provides the ability to respectively pipe standard input (stdin), standard output (stdout), and standard error output (stderr) of an external application and send and receive data in real time.
  • Provides the function to send specific signals to external applications.
  • Provides the function to retrieve the exit code of an external application.

Limitations:

  • The number of command execution resources that can be used is 3.



subprocess Global Object

Methods()/PropertiesSummaryVersionNote
subprocess.create()Creates a command execution instance.



subprocess.create(cmd[,options])

Creates a command execution instance.

NameTypeM/OSummaryNote
cmdstringmandatorySpecify the command execution path.
If command arguments are required, specify them separated by spaces after the command execution path. If a string containing a space character is to be treated as a single argument, enclose the target string range in single ' or double " quotes.
The maximum number of command characters is 4095 and the maximum number of command argument including command execution path is 31.
Ex) date, uname -a, ls -l /tmp,
cat /tmp/memo.txt, tail -f /tmp/memo.txt,
/usr/bin/myApp "hello world",
/home/user/start.sh "abc" 1 2 3
Using redirects or pipes to execute multiple commands in combination is not supported.
optionsObjectoptionalOptions
Refer to Options for details.
return{Exec}, null-{Exec} : Generated {Exec}
null : If instance creation fails due to lack of resources
If the parameter is abnormal, an exception occurs.

Options

NameTypeM/OSummaryNote
readBuffSizenumberoptionalRead buffer size [Byte]
Range: 1 - 2,147,483,647
The default value is 4096.
abortSigNonumberoptionalSignal number for forced termination
Specify the signal number to be sent when forcibly aborting the command execution process by .abort() method call, etc. Note that the execution process must always be terminable by this signal number.
Range: 1(SIGHUP), 2(SIGINT), 9(SIGKILL), 15(SIGTERM)
The default value is 15(SIGTERM).



{Exec}

Methods()/PropertiesSummaryVersionNote
.on()Registers an event handler.
.execute()Starts command execution.
.read()Reads standard output (stdout) data received from the command execution process.
.readError()Reads standard error output (stderr) data received from the command execution process.
.write()Sends data to the standard input (stdin) of the command execution process.
.sendSignal()Sends the specified signal to the command execution process.
.isBusy()Gets the execution status of the command execution process.
.getResult()Gets the exit code of the command execution process.
.abort()Aborts the command execution process forcibly.
.release()Releases a command execution resource.



Details

.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: stdout, stderr, exit
callbackfunctionmandatoryExecutes callback processing when an event occurs.
returnundefined--If the parameter is abnormal, an exception occurs.

event : ’stdout’

Executes callback processing when standard output (stdout) data is received from the command execution process and data is stored in the read buffer.

event : ’stderr’

Executes callback processing when standard error output (stderr) data is received from the command execution process and the data is stored in the read buffer.

event : ’exit’

Executes callback processing when the command execution process is exited.

Note that if the process exits with data in the standard output (stdout) and standard error output (stderr) read buffers, the callback process will not be executed immediately. It is necessary to read all data with the .read() and/or .readError() method.

.execute()

Starts command execution.

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.read([isBin])

Reads standard output (stdout) data received from the command execution process.

NameTypeM/OSummaryNote
isBinbooleanoptionalSpecify the readout data format.
true: Readout in binary data format
false: Readout in string format
The default value is false.
returnArrayBuffer, string-Readout data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
The readout data will be less than or equal to the size specified by readBuffSize. If there is no readout data, the size will be 0.
If the parameter is abnormal, an exception occurs.

.readError([isBin])

Reads standard error output (stderr) data received from the command execution process.

NameTypeM/OSummaryNote
isBinbooleanoptionalSpecify the readout data format.
true: Readout in binary data format
false: Readout in string format
The default value is false.
returnArrayBuffer, string-Readout data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
The readout data will be less than or equal to the size specified by readBuffSize. If there is no readout data, the size will be 0.
If the parameter is abnormal, an exception occurs.

.write(data)

Sends data to the standard input (stdin) of the command execution process.

NameTypeM/OSummaryNote
datastring, ArrayBuffermandatorySent data
returnnumber-Sent data size
If the sending fails, -1 is returned.
If the parameter is abnormal, an exception occurs.

.sendSignal(sigNo)

Sends the specified signal to the command execution process.

NameTypeM/OSummary             Note
sigNonumbermandatorySignal number
Range: 1 - 31
returnboolean-true: Success
false: Failure
If the parameter is abnormal, an exception occurs.

.isBusy()

Gets the execution status of the command execution process.

NameTypeM/OSummaryNote
returnboolean-Execution state
true: In process
false: Terminated or stopped state

.getResult()

Gets the exit code of the command execution process.
This method is used after the command execution process is exited.

NameTypeM/OSummaryNote
return{ExecStatus}-{ExecStatus} : Exit code

{ExecStatus}

The exit code and the exit signal number are basically exclusive, with either one having the invalid value -1.
If the command has not been executed or is in progress, all property values are set to -1.

NameTypeSummaryNote
.exitCodenumberExit code of the command execution process (0 - 255)
The exit code is set when the command execution process exits normally.
.sigNonumberExit signal number of the command execution process
If the command execution process is terminated by a signal, the signal number that caused the termination is set.
.wstatusnumberExit Status Information (Reference data)
This value is the original data in which the exit code and the exit signal information are stored.

.abort()

Aborts the command execution process forcibly.
This method is valid only when the command is in progress.

NameTypeM/OSummaryNote
returnundefined--

.release()

Releases a command execution resource.
The command in execution will be forced to terminate.

NameTypeM/OSummaryNote
returnundefined--



Object Usage Examples

Sample 1

This is a sample of command execution.
Execute the uname -p command to display CPU information.

var done = false;
var exec = subprocess.create('uname -p');

exec.on('stdout', function() {
    var resp = exec.read();
    print('response : ' + resp);
});
exec.on('exit', function() {
    done = true;
});

exec.execute();

while(1) {
    if(done) {
        break;
    }
}

exec.release();
exec = undefined;
print('done');

Sample 2

This is a sample of process communication between external applications using pipes.
The following shell script executes and establishes process communication.
Prints standard output and standard error output received from shell scripts. Then, sends "end" to the shell script via standard input to terminate the shell script.

test.sh

#!/bin/bash
cnt=0
while :
do
  read -t 1 key
  if [ -n "$key" ]; then
    echo "$key"
    break
  fi
  if [ $((${cnt} % 2)) = 1 ]; then
    echo "$cnt" 1>&2
  else
    echo "$cnt"
  fi
  cnt=`expr $cnt + 1`
done

neqto.js

var done = false;
var exec = subprocess.create('/tmp/test.sh');
if(!exec) {
    throw 'subprocess is out of resource';
}
exec.on('stdout', function() {
    var str = exec.read();
    print('stdout : ' + str.replace(/\n/g, ''));
});
exec.on('stderr', function() {
    var str = exec.readError();
    print('stderr : ' + str.replace(/\n/g, ''));
});
exec.on('exit', function() {
    done = true;
});

var tm = setTimeout(function() {
    exec.write('end\n');
}, 10000);

exec.execute();

while(1) {
    if(done) {
        var res = exec.getResult();
        print('.exitCode : ' + res.exitCode)
        print('.sigNo : ' + res.sigNo)
        break;
    }
}

clearTimeout(tm);
exec.release();
exec = undefined;
print('script done');



Updated: 2022-10-25
← 11. FileSystem13. Utils →
  • subprocess Global Object
    • subprocess.create(cmd[,options])
    • Options
  • {Exec}
  • Details
    • .on(event,callback)
    • event : ’stdout’
    • event : ’stderr’
    • event : ’exit’
    • .execute()
    • .read([isBin])
    • .readError([isBin])
    • .write(data)
    • .sendSignal(sigNo)
    • .isBusy()
    • .getResult()
    • {ExecStatus}
    • .abort()
    • .release()
  • Object Usage Examples
    • Sample 1
    • Sample 2
AboutNewsProductsFAQPrivacy Policy}
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2023 JIG-SAW INC.