.bat file in Visual Studio 2017










0















I'm trying to run a .bat file in my application. This .bat calls a JTAG application to load a firmware in microcontroller. However, I don't know why this fail in to execute the software.
If I run the .bat outside of Visual Studio it works perfectly.



I have the GUI and a Button which I will click to execute the firmware loading



To generate the command files I used a software Uniflash. This software generates a folder with all necessary files to execute the JTAG access and load the firmware.



My code is below:



 private void Button_Relay_Click(object sender, EventArgs e)

Process MSP = new Process();
MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";
MSP.StartInfo.FileName = "dslite.bat ";
MSP.Start();
Thread.Sleep(500);
MSP.WaitForExit();




However when I executed this code the compilation is ok, but when I run this code appear this error:
enter image description here



Questions:



  1. I will always generate specific bat files for each application and include the .bat folder inside the folder of VS C#, how I set up the directory path to check automatically in my software folder?


  2. Why the VS can't find the files if the path is right?
    enter image description here


  3. After my .bat run I would like to read the status of the programming ( Success or fail ) How I do it?
    Success
    enter image description here


Fail:
enter image description here










share|improve this question



















  • 2





    Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

    – mjwills
    Nov 14 '18 at 21:13






  • 2





    Have you tried to remove the space after dslite.bat?

    – Codo
    Nov 14 '18 at 21:14












  • Also see meta.stackexchange.com/questions/222735/… .

    – mjwills
    Nov 14 '18 at 21:14






  • 3





    try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

    – ADyson
    Nov 14 '18 at 21:23











  • I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

    – Markus Safar
    Nov 14 '18 at 21:41















0















I'm trying to run a .bat file in my application. This .bat calls a JTAG application to load a firmware in microcontroller. However, I don't know why this fail in to execute the software.
If I run the .bat outside of Visual Studio it works perfectly.



I have the GUI and a Button which I will click to execute the firmware loading



To generate the command files I used a software Uniflash. This software generates a folder with all necessary files to execute the JTAG access and load the firmware.



My code is below:



 private void Button_Relay_Click(object sender, EventArgs e)

Process MSP = new Process();
MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";
MSP.StartInfo.FileName = "dslite.bat ";
MSP.Start();
Thread.Sleep(500);
MSP.WaitForExit();




However when I executed this code the compilation is ok, but when I run this code appear this error:
enter image description here



Questions:



  1. I will always generate specific bat files for each application and include the .bat folder inside the folder of VS C#, how I set up the directory path to check automatically in my software folder?


  2. Why the VS can't find the files if the path is right?
    enter image description here


  3. After my .bat run I would like to read the status of the programming ( Success or fail ) How I do it?
    Success
    enter image description here


Fail:
enter image description here










share|improve this question



















  • 2





    Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

    – mjwills
    Nov 14 '18 at 21:13






  • 2





    Have you tried to remove the space after dslite.bat?

    – Codo
    Nov 14 '18 at 21:14












  • Also see meta.stackexchange.com/questions/222735/… .

    – mjwills
    Nov 14 '18 at 21:14






  • 3





    try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

    – ADyson
    Nov 14 '18 at 21:23











  • I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

    – Markus Safar
    Nov 14 '18 at 21:41













0












0








0








I'm trying to run a .bat file in my application. This .bat calls a JTAG application to load a firmware in microcontroller. However, I don't know why this fail in to execute the software.
If I run the .bat outside of Visual Studio it works perfectly.



I have the GUI and a Button which I will click to execute the firmware loading



To generate the command files I used a software Uniflash. This software generates a folder with all necessary files to execute the JTAG access and load the firmware.



My code is below:



 private void Button_Relay_Click(object sender, EventArgs e)

Process MSP = new Process();
MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";
MSP.StartInfo.FileName = "dslite.bat ";
MSP.Start();
Thread.Sleep(500);
MSP.WaitForExit();




However when I executed this code the compilation is ok, but when I run this code appear this error:
enter image description here



Questions:



  1. I will always generate specific bat files for each application and include the .bat folder inside the folder of VS C#, how I set up the directory path to check automatically in my software folder?


  2. Why the VS can't find the files if the path is right?
    enter image description here


  3. After my .bat run I would like to read the status of the programming ( Success or fail ) How I do it?
    Success
    enter image description here


Fail:
enter image description here










share|improve this question
















I'm trying to run a .bat file in my application. This .bat calls a JTAG application to load a firmware in microcontroller. However, I don't know why this fail in to execute the software.
If I run the .bat outside of Visual Studio it works perfectly.



I have the GUI and a Button which I will click to execute the firmware loading



To generate the command files I used a software Uniflash. This software generates a folder with all necessary files to execute the JTAG access and load the firmware.



My code is below:



 private void Button_Relay_Click(object sender, EventArgs e)

Process MSP = new Process();
MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";
MSP.StartInfo.FileName = "dslite.bat ";
MSP.Start();
Thread.Sleep(500);
MSP.WaitForExit();




However when I executed this code the compilation is ok, but when I run this code appear this error:
enter image description here



Questions:



  1. I will always generate specific bat files for each application and include the .bat folder inside the folder of VS C#, how I set up the directory path to check automatically in my software folder?


  2. Why the VS can't find the files if the path is right?
    enter image description here


  3. After my .bat run I would like to read the status of the programming ( Success or fail ) How I do it?
    Success
    enter image description here


Fail:
enter image description here







c# batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 21:15









Camilo Terevinto

18.7k63666




18.7k63666










asked Nov 14 '18 at 21:11









Carlos MartinsCarlos Martins

111




111







  • 2





    Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

    – mjwills
    Nov 14 '18 at 21:13






  • 2





    Have you tried to remove the space after dslite.bat?

    – Codo
    Nov 14 '18 at 21:14












  • Also see meta.stackexchange.com/questions/222735/… .

    – mjwills
    Nov 14 '18 at 21:14






  • 3





    try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

    – ADyson
    Nov 14 '18 at 21:23











  • I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

    – Markus Safar
    Nov 14 '18 at 21:41












  • 2





    Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

    – mjwills
    Nov 14 '18 at 21:13






  • 2





    Have you tried to remove the space after dslite.bat?

    – Codo
    Nov 14 '18 at 21:14












  • Also see meta.stackexchange.com/questions/222735/… .

    – mjwills
    Nov 14 '18 at 21:14






  • 3





    try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

    – ADyson
    Nov 14 '18 at 21:23











  • I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

    – Markus Safar
    Nov 14 '18 at 21:41







2




2





Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

– mjwills
Nov 14 '18 at 21:13





Your mistake is on MSP.StartInfo.FileName = "dslite.bat "; If you know the folder where that batch file is stored then that string should include that path.

– mjwills
Nov 14 '18 at 21:13




2




2





Have you tried to remove the space after dslite.bat?

– Codo
Nov 14 '18 at 21:14






Have you tried to remove the space after dslite.bat?

– Codo
Nov 14 '18 at 21:14














Also see meta.stackexchange.com/questions/222735/… .

– mjwills
Nov 14 '18 at 21:14





Also see meta.stackexchange.com/questions/222735/… .

– mjwills
Nov 14 '18 at 21:14




3




3





try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

– ADyson
Nov 14 '18 at 21:23





try single backslashes instead of double in the folder name...you've used @ to make it a literal string, so you shouldn't need to escape the slashes.

– ADyson
Nov 14 '18 at 21:23













I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

– Markus Safar
Nov 14 '18 at 21:41





I am not sure I understand your first question. What do you mean with how I set up the directory path to check automatically in my software folder?

– Markus Safar
Nov 14 '18 at 21:41












1 Answer
1






active

oldest

votes


















3














Ad 2)



About the error:



That's because you may have specified the path wrong:



Instead of



MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";


either use \ everywhere (there is only one between Test_Fixture_Visual_Studio and uniflash_windows_64) and skip the @ OR use the @ and just use one instead of two. So replace your line with this one:



MSP.StartInfo.WorkingDirectory = @"D:ProjectsTest_FixtureTest_Fixture_Visual_Studiouniflash_windows_64";





Ad 3)



About the result of your prcess:



In my opinion it is easier to not call a batch file but to call the process itself directly. In this way you can retrieve the Process.ExitCode property to retrieve the exit code of the executable (if it returns it's state via the exit code).
You can check this by calling the executable in the command shell and check the error level of the last execution by calling



echo %ERRORLEVEL%


Usually 0 indicates success, everything else indicates a failure of some kind.






share|improve this answer




















  • 1





    i thought it was a good answer

    – Ctznkane525
    Nov 14 '18 at 22:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308772%2fbat-file-in-visual-studio-2017%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Ad 2)



About the error:



That's because you may have specified the path wrong:



Instead of



MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";


either use \ everywhere (there is only one between Test_Fixture_Visual_Studio and uniflash_windows_64) and skip the @ OR use the @ and just use one instead of two. So replace your line with this one:



MSP.StartInfo.WorkingDirectory = @"D:ProjectsTest_FixtureTest_Fixture_Visual_Studiouniflash_windows_64";





Ad 3)



About the result of your prcess:



In my opinion it is easier to not call a batch file but to call the process itself directly. In this way you can retrieve the Process.ExitCode property to retrieve the exit code of the executable (if it returns it's state via the exit code).
You can check this by calling the executable in the command shell and check the error level of the last execution by calling



echo %ERRORLEVEL%


Usually 0 indicates success, everything else indicates a failure of some kind.






share|improve this answer




















  • 1





    i thought it was a good answer

    – Ctznkane525
    Nov 14 '18 at 22:11















3














Ad 2)



About the error:



That's because you may have specified the path wrong:



Instead of



MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";


either use \ everywhere (there is only one between Test_Fixture_Visual_Studio and uniflash_windows_64) and skip the @ OR use the @ and just use one instead of two. So replace your line with this one:



MSP.StartInfo.WorkingDirectory = @"D:ProjectsTest_FixtureTest_Fixture_Visual_Studiouniflash_windows_64";





Ad 3)



About the result of your prcess:



In my opinion it is easier to not call a batch file but to call the process itself directly. In this way you can retrieve the Process.ExitCode property to retrieve the exit code of the executable (if it returns it's state via the exit code).
You can check this by calling the executable in the command shell and check the error level of the last execution by calling



echo %ERRORLEVEL%


Usually 0 indicates success, everything else indicates a failure of some kind.






share|improve this answer




















  • 1





    i thought it was a good answer

    – Ctznkane525
    Nov 14 '18 at 22:11













3












3








3







Ad 2)



About the error:



That's because you may have specified the path wrong:



Instead of



MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";


either use \ everywhere (there is only one between Test_Fixture_Visual_Studio and uniflash_windows_64) and skip the @ OR use the @ and just use one instead of two. So replace your line with this one:



MSP.StartInfo.WorkingDirectory = @"D:ProjectsTest_FixtureTest_Fixture_Visual_Studiouniflash_windows_64";





Ad 3)



About the result of your prcess:



In my opinion it is easier to not call a batch file but to call the process itself directly. In this way you can retrieve the Process.ExitCode property to retrieve the exit code of the executable (if it returns it's state via the exit code).
You can check this by calling the executable in the command shell and check the error level of the last execution by calling



echo %ERRORLEVEL%


Usually 0 indicates success, everything else indicates a failure of some kind.






share|improve this answer















Ad 2)



About the error:



That's because you may have specified the path wrong:



Instead of



MSP.StartInfo.WorkingDirectory = @"D:\Projects\Test_Fixture\Test_Fixture_Visual_Studiouniflash_windows_64";


either use \ everywhere (there is only one between Test_Fixture_Visual_Studio and uniflash_windows_64) and skip the @ OR use the @ and just use one instead of two. So replace your line with this one:



MSP.StartInfo.WorkingDirectory = @"D:ProjectsTest_FixtureTest_Fixture_Visual_Studiouniflash_windows_64";





Ad 3)



About the result of your prcess:



In my opinion it is easier to not call a batch file but to call the process itself directly. In this way you can retrieve the Process.ExitCode property to retrieve the exit code of the executable (if it returns it's state via the exit code).
You can check this by calling the executable in the command shell and check the error level of the last execution by calling



echo %ERRORLEVEL%


Usually 0 indicates success, everything else indicates a failure of some kind.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 21:39

























answered Nov 14 '18 at 21:30









Markus SafarMarkus Safar

4,71241837




4,71241837







  • 1





    i thought it was a good answer

    – Ctznkane525
    Nov 14 '18 at 22:11












  • 1





    i thought it was a good answer

    – Ctznkane525
    Nov 14 '18 at 22:11







1




1





i thought it was a good answer

– Ctznkane525
Nov 14 '18 at 22:11





i thought it was a good answer

– Ctznkane525
Nov 14 '18 at 22:11



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308772%2fbat-file-in-visual-studio-2017%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto