Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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

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
mwright5
Asked:
mwright5
1 Solution
 
vinnyd79Commented:
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
 
Richie_SimonettiIT OperationsCommented:
hearing...
0
 
edwinsonCommented:
listening
0
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!

 
Richie_SimonettiIT OperationsCommented:
In wich OS you are running your VB app?
If it is NT/2000, yiu could use rexec.
0
 
Richie_SimonettiIT OperationsCommented:
0
 
Richie_SimonettiIT OperationsCommented:
0
 
mwright5Author Commented:
I want to talk from Office 95 on NT 4.0 to HP UNIX. No i am not using Samba or Visionf.
0
 
Richie_SimonettiIT OperationsCommented:
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
 
Richie_SimonettiIT OperationsCommented:
here is the same article but at Internet:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q173085
0
 
Richie_SimonettiIT OperationsCommented:
here is the same article but at Internet:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q173085
0
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now