0

..and I have no idea why. I can run exe output file from debug folder (application created in wpf), but I cant run file I need to send products into ethernet connected weight. This exe file reads .plu file (product by product) and adding them into weight memory.

Code im using:

using (StreamWriter sw = new StreamWriter(appPath + "\\Wagi\\" + cbi.Content.ToString() + "\\Kasa1.plu"))
            {
                sw.WriteLine("[MT_STAND_FIRE,PLU,WRITE,0,0,0,0]");
                foreach (DataRowView item in prodDG.Items)
                {
                   //write lines about products
                }
                sw.WriteLine("[MT_STAND_FIRE,Extra Text,WRITE,0,0,0,0]");
                sw.WriteLine("[MT_STAND_FIRE,Preset Key,Write,0,0,0,0]");

            }
            string ExecutableFilePath = appPath + @"\Wagi\" + cbi.Content.ToString() + @"\bComScale.exe";

            if (File.Exists(ExecutableFilePath))
            {
                Process.Start(ExecutableFilePath);
            }

Any ideas?

13
  • Do you get any error? Did you try to run that path in command prompt? When you concatenate path from elements use Path.Combine Commented Aug 21, 2013 at 11:52
  • I've tried to put breakpoint in string ExecutableFilePath, read value and insert text into address bar in explorer - works fine. Commented Aug 21, 2013 at 11:54
  • So when you put a breakpoint on Process.Start(...) does it execute the command and moves on, hangs, throws an error? Commented Aug 21, 2013 at 11:57
  • 1
    Point still stands. It may be the same issue. Where does the app searches for input/config files or write error file? Current folder or application folder? When you double click on the exe from explorer they are the same but when you run it from another app they may be different. Open command prompt in some random folder, past path and try to execute and see what happens Commented Aug 21, 2013 at 12:22
  • 1
    Should be easy to fix. Try Process.Start(ProcessStartInfo) and, apart from file to execute, provide ProcessStartInfo.WorkingDirectory Commented Aug 21, 2013 at 12:40

1 Answer 1

1

Application is executed fine. Problem is in executed application which seems to be looking for a config file in current folder as opposed to application folder. Since these 2 can be differ you need to use different Process.Start(ProcessStartInfo) overload which allows you to specify ProcessStartInfo.WorkingDirectory for a process.

I would also suggest to use Path.Combine when concatenating path from list of elements:

string ExecutableFilePath = System.IO.Path.Combine(appPath, "Wagi", cbi.Content.ToString(), "bComScale.exe");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.