Sending parameters from cmd line to use within script

Advertisement

tonysnowden
Joined:
Posts:
4
Location:
Leeds UK

Sending parameters from cmd line to use within script

Hi there..

I've been wrestling with WinSCP command exe with script for the past day or so.. I'm automating software install and other admin/provisioning on a local VM. We will be using the scripting to make the VM build repeatable for a small dev team.

My exe command is being called in a shell script & currently looks like this:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script="C:\VMBuild\initscript.txt" /log=C:\VMBuild\log.txt /loglevel=*
and I have an open command in the script like this:
open sftp://guser:Grp4SS1@192.168.56.119
What I want to do is pass the VM IP on the command line into initscript.txt so I can use the argument in the open cmd. That way initscript does not have to change when passed around the team that are working on diff machine IPs. Something like this
open sftp://guser:Grp4SS1@%1%
I've browsed many posts on here and been redirected to https://winscp.net/eng/docs/scripting "Script Arguments".. reading that, my assumptions to make this work are:

Gather the IP details as a variable in the shell $vmip
apply this to the execution command:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script="C:\VMBuild\scriptTEST.txt" /log=C:\VMBuild\log.txt /loglevel=* /parameter $vmip
When I run that command get this error:
Scripting does not use standalone parameters. The parameters you have specified on command-line will not be used. Your command-line syntax is probably wrong.
Opening session using command-line parameter in scripting is deprecated. Use 'open' command instead.
Searching for host...
Host "C" does not exist.
I've tested sending text values instead of the shell variable just in case but I get the same error..

Can you give me a nudge and let me know what I'm doing wrong please?

Many thanks!!
Tony :)

Reply with quote

Advertisement

tonysnowden
Joined:
Posts:
4
Location:
Leeds UK

Ok so a bit more info here... checking the log, /parameter is being read as a path on my C drive.. I can see the IP being passed afterwards

from the log
. 2022-01-07 12:57:31.747 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console=5.19.5 /consoleinstance=_1048_624 "/script=C:\VMBuild\scriptTEST.txt" "/log=C:\VMBuild\TESTlog.txt" "/loglevel=*" "C:/Users/tsnowden2/AppData/Local/Programs/Git/parameter" "192.168.56.119"
arggghhh :|

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,587
Location:
Prague, Czechia

It must be the (Linux bash?) shell that misinterprets the command line. WinSCP already gets the wrong command line. So this is not really WinSCP issue.
I do not know now to prevent that. But you can workaround it by using - (dash) instead of /:
-parameter $vmip

Reply with quote

tonysnowden
Joined:
Posts:
4
Location:
Leeds UK

Martin – thanks for your support.. yes its a bash shell & using hyphen for switch change to pass parameters works great. Cheers!

We are experiencing another weird error with our install process. The stdout feedback from installation commands we are running on our local Linux VM can hang and when nothing is printed we hit our allocated timeout value for the session (Aborted).

We thought this may be due to a memory leak issue.. the stdout from the install has a char interpretation of a spinning line.. (pipe, slash, hyphen, slash & pipe all separated by a backspace) with WinSCP not printing the stdout until it gets an EOL, the resulting line can be very large like >350k chars :/

To prove this we redirected the stdout to a file but it had no effect on the error.. the process hangs & the call from the WinSCP script does not complete.. when checking the file containing the redirected stout, that contains all the install output and a success notification. This is not linked to keep alive it just seems to crash and stop printing the stdout and therefore does not get any notification of the call command completion..

Many thanks again for support

Reply with quote

martin
Site Admin
martin avatar

Sorry, I'm lost. How is WinSCP involved in your installation process? Post the commands, scripts, logs, whatever, to demonstrate the problem.

Reply with quote

Advertisement

tonysnowden
Joined:
Posts:
4
Location:
Leeds UK

Hey martin... apologies I know that was quite a garbled post & I held back replying until today as I felt there was "too much going on outside WinSCP execution".

Anyways.. a simple update here is that any errors we experience which prompted my stream of consciousness post have been quashed by using a different shell.. I was executing a shell in cmd which spun up Git Bash.. I've since swapped to running the shell straight from a bash terminal in VSC and have seen no hanging or loss of comms errors since..

So it's another thumb up for the WinSCP functionality and a thumb down for unreliable shell in Git Bash..

Thanks again for support..
Tony

Reply with quote

Advertisement

You can post new topics in this forum