0

I installed node.js in my Windows environment, and also uglify-js

I created a sequence of uglifyjs commands and saved it in a file called uglify.js

uglifyjs K:\Temp\jsfiles\jsslashcharts.js -c -m -o K:\Temp\jsfiles\jsslashcharts.js
uglifyjs K:\Temp\jsfiles\jsslashdates.js -c -m -o K:\Temp\jsfiles\jsslashdates.js

How can I run this in node.js using VBA?

The closest thing I found on Stack Overflow is Run Node.js using VBA

So I tried (unsuccessfully)

Shell "C:\Program Files\nodejs\node.exe uglify.js", vbMaximizedFocus
gordon613
  • 2,770
  • 12
  • 52
  • 81

1 Answers1

0

The exe path contains spaces, so that will need to be double quoted, as "C:\Program Files\nodejs\node.exe" within the literal containing the command. Same goes for any arguments containing spaces.

Shell """C:\Program Files\nodejs\node.exe"" uglify.js", vbMaximizedFocus

Take a look at Quotation marks in string expressions (my emphasis)

You should include double quotation marks within the criteria argument in such a way so that when the value of the variable is evaluated, it will be enclosed within the quotation marks. Within a string, you must use two sets of double quotation marks to represent a single set of double quotation marks.

Richard
  • 25,390
  • 3
  • 25
  • 38
  • Thank you @Richard. Unfortunately fixing the quotation marks did not solve the problem - the screen just flashes and then closes. I am not even sure how to redirect any errors. Doing `> K:/temp/out.txt` or `-o K:/temp/out.txt` did not produce any output file – gordon613 Feb 06 '20 at 14:46
  • The command flashes because the wait parameter was not specified. Try adding `, true, 5000` and see if the shell window stays open for 5 seconds. Are you able to `shell` any other programs, such as `notepad` ? – Richard Feb 06 '20 at 15:42
  • Shell works with notepad... Where is the time option in Shell? See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function – gordon613 Feb 06 '20 at 16:09
  • My bad, the wait and time parameters shell parameters are VB only. The question is not new, so you might take a look at https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba – Richard Feb 06 '20 at 20:15
  • Thanks @Richard. I will look into your link and see if it helps with the debugging. My main question remains, however, which appertains to running node.js from vba. – gordon613 Feb 09 '20 at 11:11