• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AlbiScando · Oct 09, 2017 at 08:06 AM · command-lineexternal files

Running external program from c# code

Hi! i have a program on Unity and i'd like to open an external demo through my c#script. This demo is located in a different folder and to run it i normally open cdm window and write commands from there. Now i'd like everything to be done autommatically and managed by the script. So i've tried this:

     string demo = "demo";
     string Root = @"C:\Users\...\Desktop\Folder\";
     
     // call cmd and run original menge simulation
     System.Diagnostics.Process process = new System.Diagnostics.Process();
     System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
     startInfo.FileName = "cmd.exe";
           // at this point it opens the cmd window correctly
     startInfo.Arguments = System.String.Format( @"/k cd {0}\Exe", Root );
          // here it correctly changes the directory
     startInfo.Arguments = System.String.Format( @"/k menge -p ..\examples\core\{0}.xml", demo);
          // here is the problem
     process.StartInfo = startInfo;
     process.Start();
     process.WaitForExit();

When i run this code, cmd shows "menge is not recognized as an internal or external command operable program or batch file" and it sets back the directory of my unity project. The point is that if i comment the second startInfo.Arguments (so if i change the directory from code and then write manually the second command directly on cmd window), it works perfectly. But i'd like everything to be done automatically by the code, without writing anything on cmd. It seems the problem has to do with executing multiple command lines, but probably due to my lack of deep coding knowledge, i can't get how. Any idea of what i'm doing wrong? Really thanks in advance

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bilelmnasser · Oct 09, 2017 at 02:37 PM 0
Share

replace menge with the full path for your external program c://programs files/../menge.exe

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

71 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Command line error 1 Answer

Error on android game building, Win32Exception: ApplicationName='F:/Android SDK\tools\zipalign.exe', CommandLine='4 5 Answers

Build a console similar to minecraft 1 Answer

Unity Command Line Fails to Get license 1 Answer

Unity Crashes every time i add .obj file to scene 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges