VB4 - problem creating text from redirected output of shell command 
Author Message
 VB4 - problem creating text from redirected output of shell command

Hoping this is a novice question, since that would be me -

I am trying to set up an app to

run the 'net start' command
redirect it to a file in the temp directory
then check each line of that file and compare it against variable set in the
app
if the line equals the variable, set the value of that service status to
true

I have a problem creating the file and if I create it outside the app, I
have problems with carriage returns.  The variable are also be shown in a
text box and show the correct NT syntax but I get no file.  When I bring in
the file, it does not show CR but instead shows a box in between each
service.  When I modify the line input command to add Chr$(13), it just adds
the same box.

below is my code - All of the variable are defined in the form(load)

I appreciate any direction - thanks

txtConsole.Text = ""

    FtpStatus = False
    AdminStatus = False
    NtLmStatus = False
    wwwStatus = False

    If FtpStatus = False Then lblFtpStatus(2).Visible = True
    If AdminStatus = False Then lblAdminStatus(2).Visible = True
    If NtLmStatus = False Then lblNtlmStatus(2).Visible = True
    If wwwStatus = False Then lblWWWStatus(2).Visible = True

    ' Open the shell to run the net start command which will redirect the
output to a file

    retval = Shell(valRun, 0)

    ' Read the file to determine which of the Web Services are running

    Open valWCNT For Input As #1

    ' Show the file in the console window

    Do Until EOF(1)
        Line Input #1, valStartedServices
        txtConsole.Text = txtConsole.Text & vbCr & valStartedServices
    Loop

    ' If the service name is present in the file, therefore running, set the
status to True

    Do Until EOF(1)                            ' Check for end of file.
        Line Input #1, service               ' Read line of data.

            txtConsole.Text = service
            If service = valFTP Then FtpStatus = True

            If service = valAdmin Then AdminStatus = True

            If service = valNTLM Then NtLmStatus = True

            If service = valWWW Then wwwStatus = True

    Loop

    ' Close the file
    Close #1

    ' Delete the file
'TESTING BEGIN
    'Kill valWCNT
'TESTING END

    ' Show status of services
        ' Hide Unkown Statuses
        lblFtpStatus(2).Visible = False
        lblAdminStatus(2).Visible = False
        lblNtlmStatus(2).Visible = False
        lblWWWStatus(2).Visible = False

    If FtpStatus = True Then
        lblFtpStatus(0).Visible = True
    Else
        lblFtpStatus(1).Visible = True
    End If

    If AdminStatus = True Then
        lblAdminStatus(0).Visible = True
    Else
        lblAdminStatus(1).Visible = True
    End If

    If NtLmStatus = True Then
        lblNtlmStatus(0).Visible = True
    Else
        lblNtlmStatus(1).Visible = True
    End If

    If wwwStatus = True Then
        lblWWWStatus(0).Visible = True
    Else
        lblWWWStatus(1).Visible = True
    End If

    ' Update Time
    lblUpdateTime.Caption = "Last Updated " & " " & Now()

    Exit Sub



Tue, 03 Jul 2001 03:00:00 GMT  
 VB4 - problem creating text from redirected output of shell command
Look at the Ascii values of your lines:

Quote:
>     Do Until EOF(1)
>         Line Input #1, valStartedServices

For i = 1 to len(valStartedServices)
   Debug.Print Asc(Mid(valStartedServices, i))
Next i

Quote:
>         txtConsole.Text = txtConsole.Text & vbCr & valStartedServices
>     Loop

If you found those little boxes were Chr(10), you will need to add
Chr(13) in front of them.  If you found those little boxes were
Chr(13) you need to add chr(10) after them.

Or simply strip them off, and use the vbCrLf in place of vbCr.
Are they the first character: vSS = Mid(vSS, 2)   or,
are they the last character:  vSS = Left$(vSS, Len(vSS)-1))
(vSS = valStartedServices)

Unfortunately I am not familliar with the NetStart program.  If it is
a DOS program, you might redirect its output to a file using the >
(greater than) character after the filename and including the name
of the file you want the output to go to:

(Not sure what valRun was in your statement:

Quote:
>     retval = Shell(valRun, 0)

Try:
r = shell("command.com /c netstart.exe >output.txt")

where "netstart.exe" is the name of the file to run and "output.txt"
is the desired output file

To test this redirection use a command that you know has output, such
as the DIR command:

r = shell("command.com /c DIR >output.txt")

If it is a windows program, you will need to read up on its
documentation
to see if the output can be redirected.

LFS

Quote:

> Hoping this is a novice question, since that would be me -

> I am trying to set up an app to

> run the 'net start' command
> redirect it to a file in the temp directory
> then check each line of that file and compare it against variable set in the
> app
> if the line equals the variable, set the value of that service status to
> true

> I have a problem creating the file and if I create it outside the app, I
> have problems with carriage returns.  The variable are also be shown in a
> text box and show the correct NT syntax but I get no file.  When I bring in
> the file, it does not show CR but instead shows a box in between each
> service.  When I modify the line input command to add Chr$(13), it just adds
> the same box.

> below is my code - All of the variable are defined in the form(load)

> I appreciate any direction - thanks

[code cut to shorten message]


Wed, 04 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. redirect output of program run with shell command

2. VB4, WIN95: Redirecting output of a shelled process

3. Redirected Output From DOS Shell In Visual Basic 6

4. shell with dos tool output redirected to a file

5. Please help: redirecting output of shell started program

6. Probs with redirecting output of a shell started DOS-App to a file

7. Redirecting output from a SHELLed DOS Box

8. Redirecting output with Shell

9. Redirecting output in a shell (VB5)

10. using shell to exec dos app and redirect it's output

11. Shell redirect to standard output not working

12. Redirect the output of a command

 

 
Powered by phpBB® Forum Software