-3

I have a C# program that I can run successfully from inside Visual Studio with the "Start without debugging" button, and I can run it successfully by double clicking on the executable in the file explorer. But I cannot run it through Command Prompt (Oh, yeah. I'm on Windows by the way) and there is no error returned. [Also, I cannot debug the project with "Start" button in Visual Studio. For some reason it throws an error if debugged, but not simply run].

It is a simple program that prints a label on a DYMO labeler. The issue likely is with something in DYMO.

I do not recommend DYMO.

Here is the minimal reproduceable code

using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DymoSDK.Implementations;
using DymoSDK.Interfaces;
using System.IO;
namespace Testing_Relay_Board_Communication
{
    internal static class Program
    {
        static void Main()
        {
            DymoSDK.App.Init();
            string path = @"..\..\meee.dymo";
            string lines = File.ReadAllText(path);
            IEnumerable<IPrinter> printers = DymoPrinter.Instance.GetPrinters();
            printers.ElementAt(0);
            IDymoLabel ddd = DymoLabel.Instance;
            ddd.LoadLabelFromFilePath(path);

            DymoPrinter.Instance.PrintLabel(ddd, printers.ElementAt(0).Name);
            return; //stop the program here. I don't need it to do anything else



            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

I need to run this program from another program using the CLI. Does anybody know how to help?

I can only execute dymo code within a WPF project and not just a console project. Even though I can execute the dymo code before the window gets rendered.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Zeno
  • 105
  • 1
  • 2
  • 8
  • 5
    `string path = @"..\..\meee.dymo";` is a relative path... It's relative to your working directory, rather than the app's executable's directory. Maybe that's related? In CLI try navigating to your app's directory before running the exe. Or update your code to use an absolute path (or path set in config file), or to set its working directory to match the app's directory: https://stackoverflow.com/a/6719304/361842 – JohnLBevan May 25 '23 at 15:14
  • 1
    Ah, Bingo! Thanks for the help. That was it. So does that mean that if I did "C:\WINDOWS\system32>"C:\Users\amcclary\source\repos\Testing Relay Board Communication - Copy\Testing Relay Board Communication\bin\Debug\Testing Relay Board Communication.exe"" then the working directory was in system32? – Zeno May 25 '23 at 16:40
  • 2
    Correct; the application directory is where the exe is; the working directory is typically where the app's initialised from (though the working directory can be changed at runtime - e.g. by your app's code; or for example if run through Windows Task Scheduler you can set an explicit working directory in the task's configuration). – JohnLBevan May 25 '23 at 17:17
  • 1
    Some of the comments on this question/answer give a bit more info on working directories: https://stackoverflow.com/a/76037999/361842... – JohnLBevan May 25 '23 at 17:20

1 Answers1

-1

So I cannot run the executable from the command line. But I can run a link to the executable, and everything woks out just fine.

So instead of running "....\Testing Relay Board Communication - Copy\Testing Relay Board Communication\bin\Debug\Testing Relay Board Communication.exe", I just run "....\Testing Relay Board Communication\bin\Debug\Testing Relay Board Communication.exe - Shortcut.lnk" which is a link to the executable that won't run in command line.

Zeno
  • 105
  • 1
  • 2
  • 8
  • Oh, sorry. I've never actually answered my own question before. Do you mean for me to put "Answered: " in the title? – Zeno May 25 '23 at 16:36
  • 1
    I think it was flagged as not an answer, because it wasn't clear that it was an answer, opposed to something posted as an answer, that should have been an edit to the question. People post edits to their questions, as answers, all the time. - clear as mud, right! – Trenton McKinney May 25 '23 at 22:26