Ch-15 - spawn / process.env
Hi, when I run the following code
'use strict'
const { spawn } = require('child_process')
const sp = spawn(process.execPath, ['-p', 'process.env'], {
env: {SUBPROCESS_SPECIFIC: 'ENV VAR'}
})
sp.stdout.pipe(process.stdout)
console.log('total var::', Object.keys(process.env).length)
I get the result
total var:: 39
{
SUBPROCESS_SPECIFIC: 'ENV VAR',
__CF_USER_TEXT_ENCODING: '0x1F5:0x0:0xF'
}
My question is
- what and why is
__CF_USER_TEXT_ENCODING: '0x1F5:0x0:0xF'in the outout? is this expected? - the total length of
process.envis 39. is this correct or it should be 2?
I am assuming it still got other environment variables in the process because when I console.log(process.env) I see heaps of them.
What am I doing wrong ?
Thanks
Comments
-
hi @hafeez-syed
No this all looks okay - this isn't a lab exercise, you're playing with the some of the example code.
The __CF_USER_TEXT_ENCODING is injected by macOS - no matter what. It's annoying. If you look at the validate.js file of the labs for this chapter you'll see it's stripped out on macOS systems.The count is 39 because you apparently have 39 environment variables set, you're logging out the parent env not the child env here.
If you just type
envon your command line, you'll see you have a bunch of system environment variables set. That's what you're counting on the last line of you code here.0
Categories
- All Categories
- 178 LFX Mentorship
- 178 LFX Mentorship: Linux Kernel
- 774 Linux Foundation IT Professional Programs
- 383 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 103 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 11 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 32 Cloud & Containers Training
- 3 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 2 Networking Training
- 2 Open Source Best Practice Training
- 5 System Administration Training
- 1 System Engineering Training
- 4 Web & Application Development Training
- 798 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 92 Storage
- 772 Linux Distributions
- 81 Debian
- 68 Fedora
- 24 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 469 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 101 Linux Security
- 79 Network Management
- 101 System Management
- 46 Web Management
- 160 Mobile Computing
- 29 Android
- 116 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 405 Off Topic
- 127 Introductions
- 34 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 718 Software Development
- 1K Software
- 418 Applications
- 182 Command Line
- 5 Compiling/Installing
- 71 Games
- 320 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
