Go Premium for a chance to win a PS4. Enter to Win


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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Expert Comment

ID: 7073693
here is the same article but at Internet:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

971 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