Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

Passing arguements to call batch file from Vb.Net

I am calling .bat file from Vb.Net by passing Source File and Destination File Folder as Arguements.

If i call .bat file directly from cmd and pass the arguements, .bat file works !! I checked the values passed on the variables and everything looks correct to me. Still i couldn't find why my syntax fails to process the command in the .bat file. I dont get any errors or exceptions.


Dim strSourceFile As String = String.Empty
            strSourceFile = "D:\csv\TestMO.csv"

            Dim strDestPath As String = String.Empty
            strDestPath = "//home/myfolder/myfolder/"

            Dim strUserName As String = String.Empty
            strUserName = "username"

            Dim strPassword As String = String.Empty
            strPassword = "password"

            Dim strHostName As String = String.Empty
            strHostName = "hostname"

            Dim iPort As Integer
            iPort = 22

            Dim sSFTP As String = String.Empty
            sSFTP = "sftp://" & strUserName & ":" & strPassword & "@" & strHostName & ":" & iPort & strDestPath

            Dim strBatchFile As String = String.Empty
            strBatchFile = AppDomain.CurrentDomain.BaseDirectory
            'strBatchFile = strBatchFile.Replace("\bin\Debug", "\ShellScript")
            strBatchFile = strBatchFile & "callsfxcl.bat"

            Dim proc As New System.Diagnostics.Process()
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.FileName = strBatchFile
            proc.StartInfo.Arguments = String.Format("{0},{1}", strSourceFile, sSFTP)
            proc.StartInfo.CreateNoWindow = True
            proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
            proc.Start()

Open in new window

Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

proc.StartInfo.Arguments = String.Format("{0},{1}", strSourceFile, sSFTP)

shouldn't that just be:

 proc.StartInfo.Arguments = String.Format("{0} {1}", strSourceFile, sSFTP)  



eg:

callsfxcl.bat   strSourcefile,sSFTP  
    vs
callsfxcl.bat  strSourcefile sSFTP

what's in the bat file or how do you need the parameters to be called?
Avatar of chokka

ASKER

Inside the .bat file.



@Echo off


::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: This is the file on the remote site that we will be downloading

Set SRC= %1
Set DST= %2

:: This is the destination folder on the local machine (could be passed in 
:: as a parameter (e.g. %1))

Set SFXCLCMD="C:\Program Files (x86)\V Software\Clients\sfxcl.exe" %SRC% %DST%

:: Now, issue the actual SFXCL command to transfer the file
%SFXCLCMD%

:: Check for Failure
if not %errorlevel%==0 goto TRANSFER_FAILED

:: Success!
Goto Finished

::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:TRANSFER_FAILED
FOR /f "tokens=1-3 delims=: " %%a in ('Time /T') do SET CurTime=%%a:%%b%%c
echo.    %CurTime% : Transfer Failure.  
goto End

	
::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Finished
FOR /f "tokens=1-3 delims=: " %%a in ('Time /T') do SET CurTime=%%a:%%b%%c
echo %CurTime% : Transfers Completed successfuly. 

::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:End

Open in new window

Avatar of chokka

ASKER

If i called directly the .bat file from command prompt by providing sourcefile and destinationfile parameters, I am able to see the output. .Bat file is executed correctly.
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

@Kyle, Thank you !! I tried both ways. But my hunch is that something went wrong in that specific .exe file. I will try reinstalling the application.
Avatar of chokka

ASKER

Thanks