Page 1 of 1 1
Topic Options
#197414 - 2010-01-18 04:43 PM Redirection output from process in shell"..."
zwu Offline
Fresh Scripter

Registered: 2009-11-12
Posts: 6
Loc: Austria
Hi guys!

i am sitting over this very small problem of an output i need to redirect to a file in order to check it for errors:

 Code:
shell "c:\WINDOWS\system32\ftp.exe -s:"+$path+" >> "+$sourcefolder+"lookforerror.log"


even if i write it without the variables it is not working:

 Code:
shell "c:\windows\system32\ftp.exe -s:d:\ftp\ftpupload.txt > D:\FTP\lookforerror.log"


As a result i get the FTP help file as if the file was wrong.

RESULT (german):
 Code:

Überträgt Dateien zu und von einem Computer, der den TFTP-Dienst ausführt
(auch Daemon genannt).

FTP kann interaktiv verwendet werden.

FTP [-v] [-d] [-i] [-n] [-g] [-s:Dateiname] [-a] [-w:Fenstergröße] [-A]
    [Host]

  -v             Unterdrückt das Anzeigen der Rückmeldungen von
                 Remoteservern.
  -n             Unterdrückt das automatische Anmelden nach dem ersten
                 Verbindungsaufbau.
  -i             Deaktiviert die interaktive Eingabe, während mehrere
                 Dateien übertragen werden.
  -d             Aktiviert Debugging.
  -g             Deaktiviert "Globbing" des Dateinamens (siehe auch GLOB-
                 Befehl).
  -s:Dateiname   Gibt eine Textdatei an, die FTP-Befehle enthält. Die
                 Befehle werden nach dem Starten von FTP automatisch
                 ausgeführt.
  -a             Verwendet eine beliebige lokale Schnittstelle, wenn
                 Datenverbindungen gebunden werden.
  -A             Meldet den Benutzer als "Anonymus" an.
  -w:Puffergröße Überschreibt die Standardgröße des Übertragungspuffers
                 von 4096.
  Host           Gibt den Hostnamen oder die IP-Adresse des Remotehosts
                 an, zu dem eine Verbindung hergestellt wird.

Hinweis:
  - Die Befehle "mget" und "mput" akzeptieren y/n/q für yes/no/quit.
  - Verwenden Sie STRG+C zum Abbrechen von Befehlen.


but if i enter the code in the cmd window it works like a charm. i already tried substituting the >> with chr(62) but also no change.

Can anyone help? Help is appreciated!

Regards zwu

Top
#197415 - 2010-01-18 04:50 PM Re: Redirection output from process in shell"..." [Re: zwu]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Redirection is a feature of the command shell, not the command.

To get redirection to work you have to execute the command using "cmd.exe", e.g.:

 Code:
$sCommand='"'+%COMSPEC%+'" '+'/C c:\WINDOWS\system32\ftp.exe -s:"'+$path+'" > "'+$sourcefolder+'lookforerror.log" 2>&1'
"About to execute:"+@CRLF
"  "+$sCommand+@CRLF
SHELL $sCommand

Top
#197418 - 2010-01-18 07:50 PM Re: Redirection output from process in shell"..." [Re: zwu]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
You might also want to look at the WSHPipe() UDF, which returns all of the output in a string. There is a variant of WshPipe on my web site that returns a 2-element array, keeping the output and error messages separate. With my version, you could do the following:
 Code:
$Cmd = 'c:\WINDOWS\system32\ftp.exe -s:" + $path + '"'
$aResult = WshPipe($Cmd)

;Scan output messages
For Each $Line in $aResult[0]
  $Line ?  ; just display, but could do specific checks
Next

;Scan error messages
For Each $Line in $aResult[1]
  $Line ?  ; just display, but could do specific checks
Next
This is much easier and cleaner than writing to a log file, opening and enumerating the log file, and then deleting it.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197482 - 2010-01-21 08:27 AM Re: Redirection output from process in shell"..." [Re: Glenn Barnas]
zwu Offline
Fresh Scripter

Registered: 2009-11-12
Posts: 6
Loc: Austria
Works like a charm - i've gone with the WshPipe() UDF which is great!

THANKS AGAIN FOR ALWAYS HELPING!

Top
#197484 - 2010-01-21 11:54 AM Re: Redirection output from process in shell"..." [Re: zwu]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Great, but don't loose sight of Richard's comments.. WshPipe is great for capturing output, but if you ever need to pipe data through multiple commands, you still need to invoke the command interpreter as he illustrated! Redirection includes using "<", ">". or "|".

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.067 seconds in which 0.037 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org