1

I have a site that using asp.net and I am trying to create a batch script and run it.

I am using it to get latest files for a tfs workspace

the .bat only has

call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

tf get "workspacePath" /force /recursive

when I run this on the remote server by clicking on the .bat itself, it works fine and does everything I need it to do.

When I try to use this through the site it does not work.

I confirmed it does read and attempt to execute the script by adding a random .txt file in the location of the bat and have the script delete it, which worked through the site.

I have many times run batch scripts through my site, but for this specific example it is not working.

I have tried executing it via...

Process.Start(@"filepath\getStuff.bat");

I have also tried just bypassing the batch script by using psExec

Process p = new Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = @"path\PsExec.exe";
    p.StartInfo.Arguments = @"\\vdvws052 ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"" get ""workspacePath"" /force /recursive";
    p.Start();

With each way I have tried I have also added a .WaitForExit() incase that was the issue, but that didn't help either

Nick
  • 179
  • 4
  • 13
  • Make sure you specify the `StartInfo.WorkingDirectory` also see if you can execute `PsExec` from remote computer's command prompt. See if you get any error returned from `PsTools`. – Habib Aug 14 '15 at 19:30
  • I do not know why you have the double quotes inside of the `Arguments=` part.. why don't you take advantage of the string.Format function and do something like this `p.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"", SomePath, someotherparams)`....etc and add `{}` params for the number of params you will be passing – MethodMan Aug 14 '15 at 19:35
  • @MethodMan When the string is @"some text" escape characters are ignored and \" is the same as "" in order to represent a one single quote – Nick Aug 14 '15 at 19:40
  • I know the use of `@` and escape characters.. you couldn't have this issue if you were to pass in arguments using the string.Format.. perhaps you should give it a try.. – MethodMan Aug 14 '15 at 19:41

1 Answers1

0

Use the & sign for each command.

& Used to combine two commands (or more). Executes command1 and then command2

""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"" & get ""workspacePath"" /force /recursive"

&& A conditional combination. Executes command2 if command1 completes successfully

""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"" && get ""workspacePath"" /force /recursive"
Travis Boatman
  • 2,252
  • 16
  • 31