Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2002-06-11
Medium Priority
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.

Question by:mwright5
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 28

Expert Comment

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?
LVL 16

Expert Comment

ID: 7071297

Expert Comment

ID: 7072635
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Expert Comment

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

Expert Comment

ID: 7073266
LVL 16

Expert Comment

ID: 7073317

Author Comment

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

Accepted Solution

Richie_Simonetti earned 800 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


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&)


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

          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

         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)
           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

LVL 16

Expert Comment

ID: 7073692
here is the same article but at Internet:;en-us;Q173085
LVL 16

Expert Comment

ID: 7073693
here is the same article but at Internet:;en-us;Q173085
LVL 49

Expert Comment

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

Expert Comment

ID: 7978244
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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