Solved

Push a button to run a script on UNIX and display the results.

Posted on 2002-06-11
12
160 Views
Last Modified: 2010-05-02
I have taken a beginning class in visual basic; however i will be using the visual basic for applications and excell or a form in Access to do this.

I need to know how to code the command button to send the results from the script ran on a unix server to a text box.  
 
Basically I want to open a unix session and display results in a box.

0
Comment
Question by:mwright5
12 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 7071207
Do you need to run the script from your app,or can you run the script from cron and pick up the results?Are you sharing any directories on Unix with something like Samba or Visionfs?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7071297
hearing...
0
 
LVL 1

Expert Comment

by:edwinson
ID: 7072635
listening
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7073262
In wich OS you are running your VB app?
If it is NT/2000, yiu could use rexec.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7073266
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7073317
0
 

Author Comment

by:mwright5
ID: 7073587
I want to talk from Office 95 on NT 4.0 to HP UNIX. No i am not using Samba or Visionf.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 7073647
goto cmd prompt and type rexec/?
You would get all parameter for that command.
I think you could use Shell function/ShellExecute API to run it.
I think that to get the results back, you need to read Q173085 article at MSDN:

HOWTO: Create a Process for Reading and Writing to a Pipe
Article ID: Q173085
Last Reviewed: May 21, 1999

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 6.0
Microsoft Visual Basic Control Creation and Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Professional and Enterprise Editions, 32-bit only, for Windows, version 4.0

--------------------------------------------------------------------------------


SUMMARY
This example illustrates a Visual Basic application starting another process with the purpose of redirecting that process's standard IO handles. The Visual Basic application redirects the created process's standard output handle to an anonymous pipe, then proceeds to read the output through the pipe. This sample just redirects STDOUT of the new process. To redirect other handles (STDIN and STDERR), create a pipe for each handle for which redirection is desired. The Visual Basic application would read from the read ends of the pipes for the redirected STDOUT and STDERR. If STDIN redirection was desired, the Visual Basic application would write to the write end of the appropriate pipe. An example follows:


   'A pipe for redirection of STDOUT
   CreatePipe(hReadPipe1, hWritePipe1, sa, 0)

   'A pipe for redirection of STDERR
   CreatePipe(hReadPipe2, hWritePipe2, sa, 0)

   'A pipe for redirection of STDIN
   CreatePipe(hReadPipe3, hWritePipe3, sa, 0)

   'Preparing to start the process with redirected handles
   start.hStdOutput = hWritePipe1
   start.hStdError = hWritePipe2
   start.hStdInput = hReadPipe3

   'Reading output from the started process's STDOUT
   ReadFile(hReadPipe1, mybuff1, 100, bytesread, ByVal 0&)

   'Reading output from the started process's STDERR
   ReadFile(hReadPipe2, mybuff2, 100, bytesread, ByVal 0&)

   'Writing to the started process's STDIN
   WriteFile(hWritePipe3, mybuff3, 100, byteswritten, ByVal 0&)



MORE INFORMATION

Start a new project in Visual Basic. Form1 is created by default.


Add the following code to the General Declarations section of Form1:
      Option Explicit

      Private Declare Function CreatePipe Lib "kernel32" ( _
          phReadPipe As Long, _
          phWritePipe As Long, _
          lpPipeAttributes As Any, _
          ByVal nSize As Long) As Long

      Private Declare Function ReadFile Lib "kernel32" ( _
          ByVal hFile As Long, _
          ByVal lpBuffer As String, _
          ByVal nNumberOfBytesToRead As Long, _
          lpNumberOfBytesRead As Long, _
          byval lpOverlapped As Any) As Long

      Private Type SECURITY_ATTRIBUTES
          nLength As Long
          lpSecurityDescriptor As Long
          bInheritHandle As Long
      End Type

      Private Type STARTUPINFO
         cb As Long
         lpReserved As Long
         lpDesktop As Long
         lpTitle As Long
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
      End Type

      Private Type PROCESS_INFORMATION
         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type

      Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
         lpApplicationName As Long, ByVal lpCommandLine As String, _
         lpProcessAttributes As Any, lpThreadAttributes As Any, _
         ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
         ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
         lpStartupInfo As Any, lpProcessInformation As Any) As Long

      Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long

      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const STARTF_USESTDHANDLES = &H100&

      Private Sub ExecCmd(cmdline$)
          Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
          Dim start As STARTUPINFO
          Dim sa As SECURITY_ATTRIBUTES, hReadPipe As Long, hWritePipe _
          As Long
          Dim bytesread As Long, mybuff As String
          Dim i As Integer

          mybuff = String(256, Chr$(65))

          sa.nLength = Len(sa)
          sa.bInheritHandle = 1&
          sa.lpSecurityDescriptor = 0&

          ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
          If ret = 0 Then
              MsgBox "CreatePipe failed. Error: " & Err.LastDllError
              Exit Sub
          End If

       start.cb = Len(start)
       start.dwFlags = STARTF_USESTDHANDLES
       start.hStdOutput = hWritePipe

       ' Start the shelled application:
       ret& = CreateProcessA(0&, cmdline$, sa, sa, 1&, _
       NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
       If ret <> 1 Then
           MsgBox "CreateProcess failed. Error: " & Err.LastDllError
       End If

       bSuccess = ReadFile(hReadPipe, mybuff, 100, bytesread, 0&)
       If bSuccess = 1 Then
           List1.AddItem Left(mybuff, bytesread)
       Else
           MsgBox "ReadFile failed. Error: " & Err.LastDllError
       End If

          ret& = CloseHandle(proc.hProcess)
          ret& = CloseHandle(proc.hThread)
          ret& = CloseHandle(hReadPipe)
          ret& = CloseHandle(hWritePipe)
      End Sub
 



Add a CommandButton (Command1) to Form1.


Add the following code to the Command1_Click event:
      Private Sub Command1_Click()
              ExecCmd ("C:\Console\Debug\console.exe")
      End Sub


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7073692
here is the same article but at Internet:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q173085
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7073693
here is the same article but at Internet:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q173085
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7900002
Hi mwright5,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

mwright5, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7978244
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question