I'm trying to execute a nodejs command from a vbscript/classic asp page. I'm starting with lessc (less compiler) but need to use other commands too.
nodejs is installed, and I installed lessc in the global namespace (e.g. npm install -g less) I can (at the server cmd prompt) issue lessc and it works.
at the server command prompt, I can issue a command that executes lessc, such as:
lessc D:\webs\player\Layout\less\app.less > D:\webs\player\Layout\less\app.css
but when I execute it thusly inside vbscript:
dim path : path = "D:\webs\player\Layout\less\"
dim shell : shell = server.createobject("WScript.Shell")
dim errCode : errCode = shell.Run("lessc " & path & "\app.less > " & path & "\app.css", 0, true)
response.write errCode
then it does nothing. Substituting the command so that it runs CMD ahead of lessc goes one step forward: it creates a zero byte output file (app.css):
dim errCode : errCode = shell.Run("CMD /C lessc " & path & "\app.less > " & path & "\app.css", 0, true)
So it looks like it's not finding lessc, even though it's defined in the path variable; ECHO %PATH% at the servers command prompt shows the path where lessc is located. So I tried executing the full path to lessc and even that doesn't seem to work ( no errors, no output ):
dim errCode : errCode = shell.Run("CMD /C C:\Users\Administrator\AppData\Roaming\npm\lessc " & path & "\app.less > " & path & "\app.css", 0, true)
.. frustrated now .. I tried piping the output of lessc itself to a file, and it outputs a zero byte file. So it's doing something, just not executing lessc.
call shell.Run("CMD /C C:\Users\Administrator\AppData\Roaming\npm\lessc > c:\temp\lessc.txt", 0, true)
Just how do you get path variables to work in a shell.run anyway? is there a better way to execute a nodejs command server side from in vbscript/classic asp? it's going to be one of those stupid little things I always forget when working with IIS, isn't it?
Well, after a day of mucking about, I came across a github project that has a compressed node and less combo as a standalone package, that is easy to execute just using Shell.Run and you don't have to muck about with environment variables at all.
https://github.com/duncansmart/less.js-windows
So, answered my own question.
Related
I am able to download files from SFTP in CMD window, by using following code:
WinSCP.com
# Connect to the host and login using password
open user:pw#address
# get all the files in the remote directory and download them to a specific local directory
lcd C:\Users\xx\Desktop
get *.xlsx
# Close and terminate the session
exit
I searched online and found out that I can put these codes in a bat file and use
Call Shell("cmd.exe /c C:\Users\xx\Desktop\WinSCPGet.bat", 1)
However, only the first line of the bat file WinSCP.com is being executed. It will pop up the cmd window, showing this, without doing anything else.
How to execute all the lines at one time?
Thanks
The code you have is not a Windows batch file. It's one Windows command followed by WinSCP commands. The first command runs winscp.com application, which then sits and waits for input. If you eventually close it, Windows command interpreter (cmd.exe) will carry on executing the remaining commands, failing most, as they are not Windows commands. See also WinSCP script not executing in batch file and WinSCP FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
So you either have to save the commands (open to exit) to a WinSCP script file (say script.txt) and execute the script using the /script switch:
Call Shell("C:\path\winscp.com /ini=nul /script=c:\path\script.txt")
Alternatively, specify all commands on WinSCP command line, using the /command switch:
Call Shell("C:\path\winscp.com /ini=nul /command ""open user:pw#address"" ""lcd C:\Users\xx\Desktop"" ""get *.xlsx"" ""exit""")
Regarding the quotes: With the /command switch, you have to enclose each command to double-quotes. In VBA string, to use a double-quote, you have to escape it by doubling it.
Also note that you generally should use the /ini=nul switch to isolate the WinSCP script run from your WinSCP configuration. This way you can also make sure that the script will run on other machines. Your script won't, as it lacks the -hostkey switch to verify the SSH host key fingerprint. Using the /ini=nul will help you realize that.
You can have WinSCP GUI generate complete command-line (including the -hostkey) for you.
See also Automating file transfers to SFTP server with WinSCP.
I like this small and compact procedure, and use it in my own projects. No temp-files required. Fast and reliable.
Parse a string src (an absolute filepath) to uploadImageByFTP. Etc. C:\Users\user\Desktop\image.jpg, and the file will be uploaded.
Replace:
<username> with FTP-User
<password> with FTP-Password
<hostname> with FTP-hostname (etc. example.com)
<WinSCP.com path> with path on your WinSCP-client (etc. C:\Program Files (x86)\WinSCP\WinSCP.com. Caution: WinSCP.com and not WinSCP.exe)
<FTP-path> with path on your FTP-client (etc. /httpdocs/wp-content/uploads)
Sub uploadImageByFTP(src As String)
Dim script As Object: Set script = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
'Not empty
If (src <> vbNullString) Then
'Execute script
script.Run _
"""<WinSCP.com path>"" " + _
"/ini=nul " + _
"/command " + _
"""open ftp://<username>:<password>#<hostname>/"" " + _
"""cd <FTP-path>"" " + _
"""put " & """""" & src & """""" & """ " + _
"""close"" " + _
"""exit""", windowStyle, waitOnReturn
End If
End Sub
WScript.Shell is more powerful than the default Shell(), as you can append a waitOnReturn-command; this tells VBA, that further execution isn't allowed before the file(s) have been uploaded to the FTP-server.
Change windowStyle to 0, if you don't like the command prompt to open on each execution.
I'm trying to run a program with an input file.
Dim command, cfx5_exe_path, cfx_file_folder, cfx_file_name As String
command = cfx5_exe_path & " -cfx " & cfx_file_folder & cfx_file_name & ".cfx "
Shell command
so it gives an error.
the resulting value of the command in the debugger is
"c:\"Program Files"\"ANSYS Inc"\v150\CFX\bin\cfx5pre.exe -cfx c:\Users\Username\Arbeit\Programming\A321_tail_flow.cfx"
If I copy-paste that into windows cmd directly and remove first/last quotation signs, then it works perfectly.
What is the problem with Shell?
The documentation says:
If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.
and it gives a small example:
Sub test()
Dim RetVal
Dim command As String
command = "C:\WINDOWS\CALC.EXE"
RetVal = Shell(command, 1)
End Sub
Here I get Error 53: file not found as calc on Windows 7 resides somewhere else. Do you get this error?
Providing the right path to calc starts the program and returns a unique ID.
However, quoting a part of the correct path will throw the error:
command = "C:\WINDOWS\""SYSTEM32""\CALC.EXE"
but quoting the full path does not:
command = """C:\WINDOWS\SYSTEM32\CALC.EXE"""
So you must remove all embedded quotes and then quote the full path once.
I'm working with the API for Sonar (http://javadocs.sonarsource.org/4.5/apidocs/org/sonar/api/utils/command/Command.html) and it says for the function to execute commands that "the command will be executed with sh executable."
What I want to to do is just use
tslint path/to/my/code.ts
in the terminal (since this works). But the damn method excutes the line with "sh" so it looks something like this
sh tslint path/to/my/code.ts
and gives me the error
sh: 0: can't open tslint
How do I work around this to just execute "tslint" even though the command starts with sh?
Thanks for the help
EDIT: Since many of you asked what the java code looks like that produces this command (not mine, it's from an open source project):
Command command = Command.create("tslint");
command.addArgument("--config " + configFile + " --format json " + file.trim());
final EDIT:
working version:
Command command = Command.create("node");
command.addArgument(pathToTsLint);
command.addArgument("--format");
command.addArgument("json");
command.addArgument("--config");
command.addArgument(configFile);
command.addArgument(file.trim());
command.setNewShell(false);
Check in the terminal with which tslint the full path of the file.
From the terminal you can all it with
/bin/sh -c "/path/to/tslint /path/to/my/code.ts"
With the Sonar API it is:
Command command = Comman.create('/full/path/name/to/tslint');
command.addArgument("--config " + configFile + " --format json " + file.trim());
You don't need the -c parameter from the sh command, but you must use the absolute path to the tslint command.
This is my function to remove the directory after uninstalling.
Basically, in my .ism file, there are 2 .rul files(setup.rul and VerGetFileProperty.rul). I have added some code to clean the directory in setup.rul. I build, and one setup.exe is formed. While I run setup.exe, it will ask me to select the db, if I select a db, its says the db server is not found. But if I run the original setup, it will auto detect db server and install. How is the setup.exe getting created? I haven't made any changes on searching for db server part. I have just created a function to remove the directory while uninstalling.
function fnClean()
NUMBER nrv;
begin
if (ExistsDir (INSTALLDIR ^ "XYZ Dir") = EXISTS) then
SetDialogTitle(DLG_ASK_YESNO,"Delete Logs");
nrv = AskYesNo( "Do you want to delete all log files now? Say No if you prefer delete them later manually.", YES );
if ( nrv ) then
nrv = DeleteDir (INSTALLDIR ^ "XYZ Dir", ALLCONTENTS);
DeleteDir (INSTALLDIR, ALLCONTENTS);
endif;
else
DeleteDir (INSTALLDIR, ALLCONTENTS);
endif;
end;
I assume your installer either calling some exe that is generating the log files, or the log files are generated by using whatever application you are installing.
If you are using an MSI(Windows Installer) based project, you can add the files to the RemoveFile table. You'll want to use a InstallMode of 2 (remove on uninstall)
editing to expand answer
cmd_line = "cmd /c """ & objNamedArgs.Item("SQLCMD") & """ " & objNamedArgs.Item("CONNECT") & _" -i " & sql_file & " > " & log_file & " 2>&1"
-i "sqlfile" is an argument to the sqlcmd program. -i means "input" and the sqlfile will be whatever is being specified, usually a .sql script.
logfile means: redirect output of whatever command (in this case, sqlcmd) into the file specified by logfile.
The 2>&1 is already answered here.
I'm writing an API in Node.JS for an AppleScript application. The AppleScript application runs curl in a shell script in this form:
do shell script ("cd " & quoted form of myDir & "
curl http://localhost:5000/server.properties?some-value=true&next-value=something%20else&[...] -O")
It's intended to download a file called server.properties into the directory myDir with content based on the specified parameters, but for some reason when Express receives the request, it displays only this when I run console.log(res.originalUrl):
/server.properties?some-value=true
And it treats the request as if none of the other parameters are specified. Can anyone tell me what I'm doing wrong, or how to figure out where it's going wrong?
EDIT It turns out to be the way I ran the shell script. The URL needs to be quoted so that the & doesn't act as an operator in the shell script.
My solution was the following:
do shell script ("cd " & quoted form of myDir & "
curl " & quoted form of (myUrl & myQuery) & " -O")
Where myUrl is set to "http://localhost:5000/server.properties" and myQuery is set to "?some-value=true&next-value=something%20else&[...]".