|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Calling a batch file from vb.net with parametersI 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 In VB.NET I can call the batch file without the sMYDir parameter:@ECHO ON 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 eric.gofo***@gmail.com wrote:
> I had problems with spaces i the patch when I tried running the command I had an extra quote in there, it should be:> 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) > System.Diagnostics.Process.Start(ControlChars.Quote & AppDomain.CurrentDomain.BaseDirectory & "saveMylist.bat" & ControlChars.Quote & " " & sMYDir) 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() -- Show quoteHide quoteCarsten 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) --------- <eric.gofo***@gmail.com> wrote in message news:1150323777.702356.265970@g10g2000cwb.googlegroups.com... > > 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) > CT wrote:
> Try this: Thanks, that fixed it.> > 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() > -Eric "CT" <carstent@spammersgoawayintegrasol.dk> schrieb: .... or 'Process.Start(<batch file>, <arguments>)'.> 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() -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Eric,
I am not sure if I understand your question but have a look at this. http://msdn2.microsoft.com/en-us/library/system.environment.getfolderpath.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 <eric.gofo***@gmail.com> schreef in bericht Show quoteHide quote news:1150323541.604303.233050@p79g2000cwp.googlegroups.com... > 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 > eric.gofo***@gmail.com wrote:
> I have a simple batch file that I'm trying to call from a VB.NET I presume that your batch file performs other processes as well but you> application: > > @ECHO OFF > IF (%1)==() GOTO END > DIR %1 > MYDIR.TXT > :END > @ECHO ON 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?
changing the date format in vb.net
Datasets - use 1 or many? Assigning the result of a '/' division to an integer type causes rounding last ditch attempt to try and get this working error in the update Streamreader doesn't read the line properly identity /autonumber drives me nuts From Delphi to VB Referencing Function Arguments Convert Access data to XML |
|||||||||||||||||||||||