[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Writing Shell command results to a test file (VB6)

Posted on 2004-10-07
7
Medium Priority
?
456 Views
Last Modified: 2008-02-01
Greetings everyone - I have a question for the VB6 folks in the room.

I am trying to build a Shell command that will execute a command line application and write the results of the command to a text file.  Now, in DOS this is easy, I just add >>FilePath\Filename.txt to the end of the command, and viola! instant results file.

Apparently it's not that easy in VB.

Here's the code I am using:

If boolAllowLogin Then
'1. Assign values to global variables
gstrDepServer = ReadINIKey("servers", cmbEnvironment, "C:\Data\bmui.ini")
gstrUser = txtUserName
gstrPwd = txtPassword

'2. Check to see if the user has rights on the environment
strFileName = "C:\Data\LoginResults.txt"
strShellCmd = "bundlemgr"
strShellCmd = strShellCmd & " -ds " & gstrDepServer
strShellCmd = strShellCmd & " -u " & gstrUser
strShellCmd = strShellCmd & " -pwd " & gstrPwd
strShellCmd = strShellCmd & " -c list"
strShellCmd = strShellCmd & ">>" & strFileName

Shell (strShellCmd)
End If

I have set breakpoints and watched the code run through, it does build and execute the Shell Command, so I know the flag is getting set correctly, but the results file never gets created.  If I take the text that gets built above and paste it into a command line, it executes correctly and creates the file I expect to see, so I know the base syntax is correct.  I just can't seem to make VB do it correctly.  Am I missing something here?

Thanks

Greg
0
Comment
Question by:Jzaltheral
[X]
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
  • 4
  • 3
7 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12248810
Try this


strShellCmd = strShellCmd & " >> " & strFileName


add space between >>
0
 
LVL 2

Author Comment

by:Jzaltheral
ID: 12249141
EDDYKT,

That yields up the same results.

Thanks
Greg
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 total points
ID: 12249274
Or try


strShellCmd = environ("COMSPEC") & " /c bundlemgr"
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:Jzaltheral
ID: 12249371
That gives me an invalid path option.

It does return the correct path to my CMD.EXE file, but I think it's expecting bundlemgr to be there instead of where it really is.  And the bundlemgr location is in the path on the machine.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12249508
then use the fullpath for bundlemgr can you
0
 
LVL 2

Author Comment

by:Jzaltheral
ID: 12250616
As Emeril would say: Bam!

Ok, I had to tweak some things, but I did get it to work.  I had to remove the space from the directory name that the executeable lives in and then EDDYKT's solution works quite well.  Here's the completed code.

    If boolAllowLogin Then
    '1. Assign values to global variables
        gstrDepServer = ReadINIKey("servers", cmbEnvironment, "C:\Data\bmui.ini")
        gstrUser = txtUserName
        gstrPwd = txtPassword
         
    '2. Build a shell command to check for login access
        strFileName = "C:\Data\LoginResults.txt"                'Set the filename
        strShellCmd = Environ("COMSPEC") & " /c C:\BundleManager\bundlemgr"  'Set the application
        strShellCmd = strShellCmd & " -ds " & gstrDepServer     'Add the dep server
        strShellCmd = strShellCmd & " -u " & gstrUser           'Add the username
        strShellCmd = strShellCmd & " -pwd " & gstrPwd          'Add the password
        strShellCmd = strShellCmd & " -c list"                  'Add the app command
        strShellCmd = strShellCmd & " >> " & strFileName        'Add the results file
   
    '3. Exceute the Shell Command and write the results file
        RetVal = Shell(strShellCmd, vbHide)
    End If

This produces the expected results when executed.
Thanks EDDYKT.

Greg
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12250645
>>I had to remove the space from the directory name


if you have space then

""c:\program files\file""


etc
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
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…
Suggested Courses

650 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