PC Review


Reply
Thread Tools Rate Thread

Calling a batch file from vb.net with parameters

 
 
eric.goforth@gmail.com
Guest
Posts: n/a
 
      14th Jun 2006
Hello,

I have a simple batch file that I'm trying to call from a VB.NET
application:

@ECHO OFF
IF (%1)==() GOTO END
DIR %1 > MYDIR.TXT
:END
@ECHO ON

In VB.NET I can call the batch file without the sMYDir parameter:

System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory
& "saveMylist.bat ")

But when I add my parameter:

System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory
& "saveMylist.bat " & sMYDir)

I get:

"The system cannot find the file specified"

Does anyone have an idea how to work around this? I don't want to hard
code the path in my batch file.

AppDomain.CurrentDomain.BaseDirectory is:

"C:\Documents and Settings\MyUser\My Documents\Visual Studio
2005\Projects\MyProj\bin\Debug\"

I had problems with spaces i the patch when I tried running the command
from a command prompt, so I tried changing the commandline to:

System.Diagnostics.Process.Start(ControlChars.Quote &
AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" " &
ControlChars.Quote & " " & sMYDir)

and get the same error.

I CAN run the complete concatenated string returned by
(ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory &
"saveMylist.bat" " & ControlChars.Quote & " " & sMYDir) from the
command prompt with no errors, but it doesn't work when I call it from
System.Diagnostics.Process.Start.

Thanks,
Eric

 
Reply With Quote
 
 
 
 
eric.goforth@gmail.com
Guest
Posts: n/a
 
      14th Jun 2006

eric.gofo...@gmail.com wrote:

> I had problems with spaces i the patch when I tried running the command
> from a command prompt, so I tried changing the commandline to:
>
> System.Diagnostics.Process.Start(ControlChars.Quote &
> AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" " &
> ControlChars.Quote & " " & sMYDir)
>


I had an extra quote in there, it should be:

System.Diagnostics.Process.Start(ControlChars.Quote &
AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" &
ControlChars.Quote & " " & sMYDir)

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      15th Jun 2006
Eric,

I am not sure if I understand your question but have a look at this.

http://msdn2.microsoft.com/en-us/lib...olderpath.aspx

if you are using version 2005 you can as well look to this.

http://msdn2.microsoft.com/en-us/library/0b485hf7(vs.80).aspx

I hope this helps,

Cor

<(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hello,
>
> I have a simple batch file that I'm trying to call from a VB.NET
> application:
>
> @ECHO OFF
> IF (%1)==() GOTO END
> DIR %1 > MYDIR.TXT
> :END
> @ECHO ON
>
> In VB.NET I can call the batch file without the sMYDir parameter:
>
> System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory
> & "saveMylist.bat ")
>
> But when I add my parameter:
>
> System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory
> & "saveMylist.bat " & sMYDir)
>
> I get:
>
> "The system cannot find the file specified"
>
> Does anyone have an idea how to work around this? I don't want to hard
> code the path in my batch file.
>
> AppDomain.CurrentDomain.BaseDirectory is:
>
> "C:\Documents and Settings\MyUser\My Documents\Visual Studio
> 2005\Projects\MyProj\bin\Debug\"
>
> I had problems with spaces i the patch when I tried running the command
> from a command prompt, so I tried changing the commandline to:
>
> System.Diagnostics.Process.Start(ControlChars.Quote &
> AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" " &
> ControlChars.Quote & " " & sMYDir)
>
> and get the same error.
>
> I CAN run the complete concatenated string returned by
> (ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory &
> "saveMylist.bat" " & ControlChars.Quote & " " & sMYDir) from the
> command prompt with no errors, but it doesn't work when I call it from
> System.Diagnostics.Process.Start.
>
> Thanks,
> Eric
>



 
Reply With Quote
 
CT
Guest
Posts: n/a
 
      15th Jun 2006
Try this:

Dim process As New System.Diagnostics.Process
Dim startInfo As New ProcessStartInfo( _
ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory &
"saveMylist.bat", sMYDir)
process.StartInfo = startInfo

process.Start()


--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
---------
Voodoo Programming: Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
everything. (Karl Lehenbauer)
---------
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> eric.gofo...@gmail.com wrote:
>
>> I had problems with spaces i the patch when I tried running the command
>> from a command prompt, so I tried changing the commandline to:
>>
>> System.Diagnostics.Process.Start(ControlChars.Quote &
>> AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" " &
>> ControlChars.Quote & " " & sMYDir)
>>

>
> I had an extra quote in there, it should be:
>
> System.Diagnostics.Process.Start(ControlChars.Quote &
> AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" &
> ControlChars.Quote & " " & sMYDir)
>



 
Reply With Quote
 
eric.goforth@gmail.com
Guest
Posts: n/a
 
      15th Jun 2006

CT wrote:
> Try this:
>
> Dim process As New System.Diagnostics.Process
> Dim startInfo As New ProcessStartInfo( _
> ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory &
> "saveMylist.bat", sMYDir)
> process.StartInfo = startInfo
>
> process.Start()
>

Thanks, that fixed it.

-Eric

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Jun 2006
"CT" <(E-Mail Removed)> schrieb:
> Dim process As New System.Diagnostics.Process
> Dim startInfo As New ProcessStartInfo( _
> ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory &
> "saveMylist.bat", sMYDir)
> process.StartInfo = startInfo
>
> process.Start()


.... or 'Process.Start(<batch file>, <arguments>)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      15th Jun 2006
(E-Mail Removed) wrote:

> I have a simple batch file that I'm trying to call from a VB.NET
> application:
>
> @ECHO OFF
> IF (%1)==() GOTO END
> DIR %1 > MYDIR.TXT
> :END
> @ECHO ON


I presume that your batch file performs other processes as well but you
can duplicate this functionality using the classes in the System.IO
namespace. What is done with the output file, mydir.txt, after you have
created it?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling multiple batch files from within a batch file yawnmoth Windows XP General 3 26th May 2008 06:47 PM
Batch File Parameters =?Utf-8?B?Um9nZXI=?= Windows XP General 12 27th Jan 2006 03:19 AM
Calling a batch file in context menu with _multiple_ parameters files Vinzz Windows XP Help 1 20th Sep 2005 10:49 PM
Calling Batch within a Batch file Bobby Stiklus Microsoft Windows 2000 Developer 1 27th Apr 2004 06:40 PM
Calling Batch within a Batch File ChuckR Microsoft Windows 2000 Developer 0 22nd Apr 2004 02:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.