windows-cmd
Execute windows command via code. All functions is asynchronous.
If you have any question, issue or bug report feel free to ask.
Table of content
Installation
via npm:
npm i -S windows-cmd
Usage
const cmd =
checkEnv(variable)
asynchronous function
Check if environment variable exists
- {string} variable - environment variable name
try await cmd // => true or false catch err console // => windows error
checkEnvValue(variable, value)
asynchronous function
Check if value exists in environment variable
-
{string} variable - environment variable name
-
{string} value - value of environment variable
try await cmd // => true or false catch err console // => windows error
listEnvValues(variable)
asynchronous function
List values of environment variable
- {string} variable - environment variable name
try await cmd // > returns a string catch err console // => windows error
Result:
PATH=C:\Users\Desenvolvimento\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files \oracle-instant-client;C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Python27;C:\Python27\Scripts;C:\Program Files \Borland\Delphi7\Bin;C:\Program Files \Borland\Delphi7\Projects\Bpl;C:\totvs\CorporeRM\API;C:\app\Desenvolvimento\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs;C:\Users\Desenvolvimento\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\Desenvolvimento\AppData\Local\Programs\Python\Python37;C:\Users\Desenvolvimento\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perlPATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
setSystemEnv(variable, value)
asynchronous function
Add a new value to the system environment variable. If the variable does not exist it will be createds
-
{string} variable - environment variable name
-
{string} value - value of environment variable
try await cmd // => true or false catch err console // => windows error
setUserEnv(variable, value)
asynchronous function
Add a new value to the user environment variable. If the variable does not exist it will be createds
-
{string} variable - environment variable name
-
{string} value - value of environment variable
try await cmd // => true or false catch err console // => windows error
checkFile(filePath, fileName)
asynchronous function
Check if file/folder exists
-
{string} filePath - path to check
-
{string} fileName - file name
try await cmd // => true or false catch err console // => windows error
listFile(folderPath)
asynchronous function
List all folder and files
- {string} folderPath - path to list
try await cmd // => returns a string catch err console // => windows error
Result:
19/07/2019 15:47 <DIR> .19/07/2019 15:47 <DIR> ..19/07/2019 15:46 0 file1.txt19/07/2019 15:46 0 file2.txt19/07/2019 15:47 0 file3.pdf 3 arquivo 0 bytes 2 pasta 31.755.882.496 bytes disponíveis
copyFile(filePath, toPath)
asynchronous function
Copy file/folder
-
{string} filePath - file path
-
{string} toPath - path to paste
try // Copy my-pdf.pdf and paste it in paste-folder await cmd // => true or false catch err console // => windows error
mkDir(folderPath)
asynchronous function
Create a folder
- {string} folderPath - folder path with name
try // create logs folder await cmd // => true or false catch err console // => windows error
checkWinrar()
asynchronous function
Checks if winrar is installed
try await cmd // => true or false catch err console // => windows error
winrarExtract(filePath, toPath)
asynchronous function
Extract .rar file
-
{string} filePath - file path
-
{string} toPath - path to extract
try await cmd // => true or false catch err console // => windows error
exec(command)
asynchronous function
Execute windows command
- {string} command - cmd command
try await cmd // => true or false catch err console // => windows error
Changelog
See the update notes at CHANGELOG.
License
MIT License
Copyright ® 2019 Victor Gianvechio
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.