<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Run a bat file with argument via server method</title><link>https://www.aras.com/community/f/development/19629/run-a-bat-file-with-argument-via-server-method</link><description>Hello Everyone, 
 I would like to run a bat file with argument on server via server method. I saw the same topic on forum in several year ago but they also have no solution. 
 https://community.aras.com/f/archive/2847/developers-forum---trying-to-execute</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Run a bat file with argument via server method</title><link>https://www.aras.com/community/thread/5095?ContentTypeID=1</link><pubDate>Wed, 20 May 2020 16:08:46 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:8bdaef9c-a7ec-4d02-9cda-1df207d2e0e4</guid><dc:creator>Gopikrishnan</dc:creator><description>&lt;p&gt;Glad to hear. Stay safe..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Run a bat file with argument via server method</title><link>https://www.aras.com/community/thread/5088?ContentTypeID=1</link><pubDate>Wed, 20 May 2020 08:18:54 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:5426e8c4-5468-47ad-a4f2-1741e196c616</guid><dc:creator>DucTran</dc:creator><description>&lt;p&gt;I Tried run server method with your Hello.bat, It&amp;#39;s worked fine.&lt;/p&gt;
&lt;p&gt;The problem is the my bat file :) . Thanks for your support!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Run a bat file with argument via server method</title><link>https://www.aras.com/community/thread/5078?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 17:20:19 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:a836edc5-2754-481e-b62d-36ef2a56457d</guid><dc:creator>Gopikrishnan</dc:creator><description>&lt;p&gt;Hi DucTran&lt;/p&gt;
&lt;p&gt;Hope you have modified the directory, bat file name in above method. If it is executed, might be the bat file executed correctly. Can you confirm what is there in the bat file. If you want to test whether the method is working or not, you can keep below lines in bat file and run&lt;/p&gt;
&lt;p&gt;Open Notepad&lt;/p&gt;
&lt;p&gt;Copy below line and save as Hello.bat&lt;/p&gt;
&lt;p&gt;@echo off&lt;br /&gt;@echo Testing Bat File Operation from ARAS Innovator&amp;gt; output.txt&lt;/p&gt;
&lt;p&gt;Copy this bat file to the input directory as per the method&lt;/p&gt;
&lt;p&gt;Execute the method&lt;/p&gt;
&lt;p&gt;Verify the directory provided in the method for output&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Run a bat file with argument via server method</title><link>https://www.aras.com/community/thread/5073?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 07:30:04 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:6dc9f050-39b8-40a6-85f5-a000b6d887cb</guid><dc:creator>DucTran</dc:creator><description>&lt;p&gt;I have tried your code, it&amp;#39;s go to the end of line (return this;) fine without exception. but bat file is not execute, the output.txt is not created.&lt;/p&gt;
&lt;p&gt;I am sure the folder of bat file on server is shared for everyone.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Run a bat file with argument via server method</title><link>https://www.aras.com/community/thread/5071?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 06:11:14 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:e2b9eb3f-1b16-496c-94e1-c6328953cce5</guid><dc:creator>Gopikrishnan</dc:creator><description>&lt;p&gt;&lt;strong&gt;Hi DucTran&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use below server method to run the bat file&amp;nbsp;&lt;/p&gt;
&lt;p&gt;string inputPath = string.Format(@&amp;quot;C:\Backup\Test&amp;quot;);&amp;nbsp; &amp;nbsp;//Directory of the Bat file&lt;br /&gt;System.Diagnostics.Process command = new System.Diagnostics.Process();&lt;br /&gt;command.StartInfo.FileName = Path.Combine(inputPath, &amp;quot;Hello.bat&amp;quot;); // Bat file Name&lt;br /&gt;string outputPath = Path.Combine(inputPath, &amp;quot;output.txt&amp;quot;); //Output file&lt;br /&gt;command.StartInfo.Arguments = string.Format(&amp;quot;\&amp;quot;{0}\&amp;quot; \&amp;quot;{1}\&amp;quot; \&amp;quot;{2}\&amp;quot;&amp;quot;, inputPath, outputPath, inputPath);&lt;br /&gt;command.StartInfo.UseShellExecute = false;&lt;br /&gt;command.StartInfo.CreateNoWindow = true;&lt;br /&gt;command.StartInfo.WorkingDirectory = inputPath;&lt;br /&gt;command.Start();&lt;br /&gt;if (!command.WaitForExit(3000)) //Execution allowed time to prevent system hung&lt;br /&gt;{&lt;br /&gt; throw new Exception(string.Format(&amp;quot;The process &amp;#39;{0}&amp;#39; is not responding&amp;quot;, command.StartInfo.FileName));&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;if (command.ExitCode != 0)&lt;br /&gt;{&lt;br /&gt; throw new Exception(string.Format(&amp;quot;The process &amp;#39;{0}&amp;#39; has finished with error (ErrorCode={1})&amp;quot;, command.StartInfo.FileName, command.ExitCode));&lt;br /&gt;}&lt;br /&gt;return this;&lt;/p&gt;
&lt;p&gt;Note: If you get access denied error, provide access to that folder to everyone an try&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank You&lt;/p&gt;
&lt;p&gt;Gopikrishnan R&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>