Posts

Showing posts with the label Cmd

Change Directory In Node.js Command Prompt

Image
Answer : That isn't the Node.js command prompt window. That is a language shell to run JavaScript commands, also known as a REPL. In Windows, there should be a Node.js command prompt in your Start menu or start screen: Which will open a command prompt window that looks like this: From there you can switch directories using the cd command. To switch to the another directory process.chdir("../"); If you mean to change default directory for "Node.js command prompt", when you launch it, then (Windows case) go the directory where NodeJS was installed find file nodevars.bat open it with editor as administrator change the default path in the row which looks like if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%" with your path. It could be for example if "%CD%\"=="%~dp0" cd /d "c://MyDirectory/" if you mean to change directory once when you launched "Node.js command prom...

Batch File For PuTTY/PSFTP File Transfer Automation

Answer : You need to store the psftp script (lines from open to bye ) into a separate file and pass that to psftp using -b switch: cd "C:\Program Files (x86)\PuTTY" psftp -b "C:\path\to\script\script.txt" Reference: https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-option-b EDIT: For username+password: As you cannot use psftp commands in a batch file, for the same reason, you cannot specify the username and the password as psftp commands. These are inputs to the open command. While you can specify the username with the open command ( open <user>@<IP> ), you cannot specify the password this way. This can be done on a psftp command line only. Then it's probably cleaner to do all on the command-line: cd "C:\Program Files (x86)\PuTTY" psftp -b script.txt <user>@<IP> -pw <PW> And remove the open , <user> and <PW> lines from your script.txt . Reference: https://the.earth.li...

Assign Command Output To Variable In Batch File

Answer : A method has already been devised, however this way you don't need a temp file. for /f "delims=" %%i in ('command') do set output=%%i However, I'm sure this has its own exceptions and limitations. This post has a method to achieve this from (zvrba) You can do it by redirecting the output to a file first. For example: echo zz > bla.txt set /p VV=<bla.txt echo %VV% You can't assign a process output directly into a var, you need to parse the output with a For /F loop: @Echo OFF FOR /F "Tokens=2,*" %%A IN ( 'Reg Query "HKEY_CURRENT_USER\Software\Macromedia\FlashPlayer" /v "CurrentVersion"' ) DO ( REM Set "Version=%%B" Echo Version: %%B ) Pause&Exit http://ss64.com/nt/for_f.html PS: Change the reg key used if needed.

Batch Character Escaping

Answer : This is adapted with permission of the author from the page Batch files - Escape Characters on Rob van der Woude's Scripting Pages site. TLDR Windows (and DOS) batch file character escaping is complicated: Much like the universe, if anyone ever does fully come to understand Batch then the language will instantly be replaced by an infinitely weirder and more complex version of itself. This has obviously happened at least once before ;) Percent Sign % % can be escaped as %% – "May not always be required [to be escaped] in doublequoted strings, just try" Generally, Use a Caret ^ These characters "may not always be required [to be escaped] in doublequoted strings, but it won't hurt": ^ & < > | Example: echo a ^> b to print a > b on screen ' is "required [to be escaped] only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used" ` is "required [to be es...

Batch - Copy File Using Relative Path

Answer : if you start your path with \ , it's an absolute, not a relative path. Try copy "Debug\text.txt" "..\..\new" instead