Application.StartupPath and a command

J

jcrouse

I am trying to run a command from a command prompt using the shell command.
Here is the syntax I want to execute:

Shell(lblMameExePath.Text & " -listinfo >" & Application.StartupPath &
"\MameGames.cfg", AppWinStyle.NormalFocus, True)


The problem is that the parameter Application.StartupPath has spaces
(C:\Program Files, for instance) and won't execute from a command prompt
without being incased in quotes. I can't figure out the proper syntax with
my quotes.

Help,
John
 
H

Herfried K. Wagner [MVP]

* "jcrouse said:
I am trying to run a command from a command prompt using the shell command.
Here is the syntax I want to execute:

Shell(lblMameExePath.Text & " -listinfo >" & Application.StartupPath &
"\MameGames.cfg", AppWinStyle.NormalFocus, True)


The problem is that the parameter Application.StartupPath has spaces
(C:\Program Files, for instance) and won't execute from a command prompt
without being incased in quotes. I can't figure out the proper syntax with
my quotes.

\\\
Shell(lblMameExePath.Text & " -listinfo >""" & Application.StartupPath & "\MameGames.cfg""", AppWinStyle.NormalFocus, True)
///
 
J

jcrouse

Well at least in the watch window the correct syntax seems to be this code:



Shell(lblMameExePath.Text & " -listinfo >" & """" & Application.StartupPath
& "\Games.cfg" & """", AppWinStyle.NormalFocus, True)



Here is what it displays in the watch window:

Watch string:

lblMameExePath.Text & " -listinfo >" & """" & Application.StartupPath &
"\MameGames.cfg" & """"



String Value:

"C:\Mame\Mame.exe -listinfo >"C:\VB Projects\XLM
App\Writer\bin\MameGames.cfg""



If you remove the beginning and end quotes because it is a string it is the
exact syntax I need. From a command prompt it works great. However, from
within the code it does nothing.





Ken I also tried your code and it too looked correct in the watch window but
failed to create the file. Both of our syntax's go through the motions. It
takes about 60 seconds to create. It is a 20MB text file. However, after
execution, no file appears. I have searched my entire harddrive and NOTHING.
I'm stumped. The tought thing is that it will still scroll all the text to
the screen if the path is bad so I can't really tell whether its writing a
file or just outputting to the screen. Any more ideas?

The next thing after I get this working will be to create the file the first
time during the install routine. I'm not quite sure how to do this either,
but haven't looked into it yet.

Thank you,
John



Herfried K. Wagner said:
\\\
Shell(lblMameExePath.Text & " -listinfo >""" & Application.StartupPath &
"\MameGames.cfg""", AppWinStyle.NormalFocus, True)
 
J

jcrouse

Herfried........Thank you but that code is way over my head. Can it really
take THAT MUCH just to send a string to a command prompt? There has to be an
easier way.

Thanks again,
John
 
H

Herfried K. Wagner [MVP]

* "jcrouse said:
Herfried........Thank you but that code is way over my head. Can it really
take THAT MUCH just to send a string to a command prompt? There has to be an
easier way.

It's not as easy. You will have to launch "cmd.exe" and then call the
other executable with "> ..." specified. The "> ..." part is a feature
of the command shell.
 
J

jcrouse

Well, I've been trying for three or four hours with no luck. It seems to not
like the redirect ">" part. Anyone have any other ideas?

Thanks,
John
 
J

jcrouse

Well I got it working, kind of.....Here is the latest. This code works.

If lblMameExePath.Text <> "" Then

Dim sr As StreamWriter = File.CreateText("C:\games.bat")

sr.WriteLine(lblMameExePath.Text & " -listinfo >""" &
Application.StartupPath & "\mamegames.cfg""")

sr.Close()

Dim response As String

response = MsgBox("You will be notified when the operation is
complete", MsgBoxStyle.OKOnly, "CPViewer")

Shell("C:\games.bat", AppWinStyle.NormalFocus, True)

response = MsgBox("Your file has been created successfully.",
MsgBoxStyle.OKOnly, "CPViewer")

Else

Dim response As String

response = MsgBox("You must first specify the path to your mame
executable", MsgBoxStyle.OKOnly, "CPViewer")

End If


As long as I specify the path in the shell command. If I use
Application.StartupPath & "\games.bat" in the sr.WriteLine line it
write the file great. However, if I use the same exact syntax in the shell
command is says that the file does not exist. Even the watch window has the
exact same string for both parameters. Can anyone explain this behavior? I
really hate to hard code paths in an application.

Thank you,
John
 
J

jcrouse

Resolved! I specified the criteria in a variable and then used the variable
in both places and it works. I'm confused. Oh well.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top