0

I am checking for the number of files I have in a Unix Directory, and I am trying to get that number in a VBScript variable.

My code:

set oShell = CreateObject("WScript.Shell")
oShell.Run "C:\PLINK.EXE -ssh user@host -pw abc find /my/files -name '*333*' | wc -l > C:\files\res.txt"
set oShell = Nothing

The above code didn't write in the .txt file. I was thinking that i'll read the .txt file using vbscript and get the count.

Is there a direct way to to get the count returned from wc -l in a vbscript variable.

thank you.

1 Answer 1

2

You need a shell (%comspec%) to get shell features like redirection (cf. here). So change

oShell.Run "C:\PLINK.EXE -ssh user@host -pw abc find /my/files -name '*333*' | wc -l > C:\files\res.txt"

to

oShell.Run "%comspec% /c C:\PLINK.EXE -ssh user@host -pw abc find /my/files -name '*333*' | wc -l > C:\files\res.txt"

after you have checked that

C:\PLINK.EXE -ssh user@host -pw abc find /my/files -name '*333*' | wc -l > C:\files\res.txt

'works' from a console.

In case of trouble study the docs for .Run (parameters, return value) and .Exec (Stdout/Stderr capturing) and simplify (e.g. no | wc -l).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.