Is it possible to (and if so, how do I) make a single program work both as a console application and a GUI version using Delphi 2007?  What I am after is that if the program is run with the appropriate command-line options, it should function as a console program, printing output to the console using WRITELN, but if no command line arguments are given it should run as a normal Delphi GUI application?  The catch is that when running as a console application, the command line interpreter waits for the application to terminate before allowing you to enter a new command, whereas a GUI application started from the command line immediately returns you to the command line and the GUI application is started in a detached process. I want this behaviour retained.  I don't mind something like this:     IF GUI THEN StartApplicationAsGUI(ParamStr(0))   ie. I don't mind that I'll have to restart the application using some form of EXECUTE call to start it in GUI mode if needed, as long as the command line interface returns to the command line input when the GUI version is started.  I'd prefer a solution/suggestion that is along the lines of:     &lt;Parse Comnand Line&gt;   IF ConsoleMode THEN   &nbsp;&nbsp;&nbsp;RunConsole(Parameters)   ELSE BEGIN   &nbsp;&nbsp;&nbsp;Application.Initialize;   &nbsp;&nbsp;&nbsp;Application.CreateForm(...)   &nbsp;&nbsp;&nbsp;Application.Run;   END   (or vice-versa, ie. doing things a special way if GUI mode)  so that I can still use Delphi's IDE and VCL when making the GUI interface...
122442
I want to make a  program that can be run as a CLI or GUI application depending on what flags are passed into it. Can this be done?  I have found these related questions, but they don't exactly cover my situation:
77250
My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.  I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:     Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point   Huh?  Yes it does... and it was all working 15 min earlier.  Sure, I can believe that I accidentally hit something or done something before I closed it up... but what?  How do I troubleshoot this?    My Program.cs file looks like this:  using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading;  namespace SimpleAIMLEditor {     static class Program     {         [STAThread]         static void Main()         {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);              Application.Run(new mainSAEForm());         }     } }   ...and there are some comments in there.    There are no other errors.  Help?
122893
The Goal: I would like to open a program from my ubuntu server in my windows 7 desktop.  Steps Taken: Putty > SSH > X11 check 'enable port forwarding' I have started VNC Viewer in listening mode started putty ssh session apt get install xinit startx &amp; geany (it's a c language ide; it uses the GUI so I"m using it to test x forwarding)    Error Messages: geany returns "cannot open display" startx returns "setversion 1.4 failed"    I'm working on Windows 7 and headless Ubuntu Server 12.04 LTS  Obviously I forgot something, but I'm having difficulty figuring out what. The goal is to not use sudo apt get install desktop, since I only want to use one program at a time, and anyway my server isn't hooked up to a monitor.   Any ideas? Questions? Thanks for your help! Curios
81192
During development (and for debugging) it is very useful to run a Java class' public static void main(String[] argv)  method directly from inside Eclipse (using the Run As context menu).  Is there a similarily quick way to specify command line parameters for the run? What I do now is go to the "Run Dialog", click through the various settings to the tab where I can specify VM and program arguments and enter them there.  Too many steps, plus I do not want to mix the more permanent runtime configuration settings with the one-off invokation parameters. What I want instead is to check a box somewhere (or have a separate menu item "Run as Java application with command line") and then be prompted for the commandline every time (with a nice history).
90919
I know how to program Console application with parameters, example : myProgram.exe param1 param2.  My question is, how can I make my program works with |, example : echo "word" | myProgram.exe?
83278
Edit: Since it appears that there's either no solution, or I'm doing something so non-standard that nobody knows - I'll revise my question to also ask: What is the best way to accomplish logging when a python app is making a lot of system calls?  My app has two modes.  In interactive mode, I want all output to go to the screen as well as to a log file, including output from any system calls.  In daemon mode, all output goes to the log.  Daemon mode works great using os.dup2().  I can't find a way to "tee" all output to a log in interactive mode, without modifying each and every system call.    In other words, I want the functionality of the command line 'tee' for any output generated by a python app, including system call output.  To clarify:   To redirect all output I do something like this, and it works great:  # open our log file so = se = open("%s.log" % self.name, 'w', 0)  # re-open stdout without buffering sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)  # redirect stdout and stderr to the log file opened above os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(se.fileno(), sys.stderr.fileno())   The nice thing about this is that it requires no special print calls from the rest of the code.  The code also runs some shell commands, so it's nice not having to deal with each of their output individually as well.  Simply, I want to do the same, except duplicating instead of redirecting.  At first thought, I thought that simply reversing the dup2's should work.  Why doesn't it?  Here's my test:   import os, sys  ### my broken solution: so = se = open("a.log", 'w', 0) sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)  os.dup2(sys.stdout.fileno(), so.fileno()) os.dup2(sys.stderr.fileno(), se.fileno()) ###  print("foo bar")  os.spawnve("P_WAIT", "/bin/ls", ["/bin/ls"], {}) os.execve("/bin/ls", ["/bin/ls"], os.environ)   The file "a.log" should be identical to what was displayed on the screen.
10858
I'm firing off a Java application from inside of a C#  console application. It works fine for the case where the Java application doesn't care what the "default" directory is, but fails for a Java application that only searches the current directory for support files.  Is there a process parameter that can be set to specify the default directory that a process is started in?
68588
When I launch certain programs from the command line like eclipse and document viewer in 11.10 it spews a load of information that seems inconsequential.   Also when they are run in the background they sometimes continue to produce output to the terminal which I am currently working on, which is irritating.  I would like them just launch and keep the background stuff in the background. My reasoning is that if you launch these programs through the GUI (eg double clicking on an icon) these messages are never shown to me, so I don't need them in the command line.
25822
If you have gnome-terminal running, and want a new instance of the program, you might think that running gnome-terminal &amp; from a shell would do the trick.  Astonishingly, this new instance behaves like some insipid Windows or Mac program; it only sends a message to the existing, running gnome-terminal to create a new window. If this one gnome-terminal process crashes, you lose all of the terminal windows!  (Of course, each window has its own shell, which is an independent process, but the actual terminal emulator and its GUI are managed from a single instance of the application.)  How can we create independent instances of gnome-terminal, each running in their own process, so that killing that process only destroys the window(s) associated with that process?
30406
I have a simple one line command which works perfectly in terminal, but does not work in the "Startup Applications" app thing.  The line of code is : xmodmap /home/seph/Code/Ubuntu\ Scripts/Xmodmap  It's not that much of a hassle to copy it from "Startup Applications" and paste it into terminal, but I don't really get why it isn't working.  I followed someone else's instructions to do it in the first place, so maybe I did something wrong?  In any case, wouldn't it be the obvious and logical assumption that it just types whatever you put in it into Terminal?
67350
First: I'm obviously not talking about logging in and then automatically launching Terminal.app.  In , you used to be able to type &gt;console in the username field on the login screen and go directly into a command line terminal session.  I haven't done it in years until the other day. However, now, when I try it, my computer just locks up. I can't cancel, and it never sends me to a terminal session.  Is it even possible to do this anymore? If not, does anybody know when it was removed? It seems odd that typing &gt;console would cause the machine to lock up if it wasn't recognizing it in some way.
113657
For running direct commands, there are two ways.   Either run in Terminal Or run from the "Run Command" dialogue (screen shown below) obtained from Alt+F2     Then, Is there any difference between them? (working same &amp; shell) or redirects to same?
87449
I have a python app and java app. The python app generates input for the java app and invokes it on the command line.  I'm sure there must be a more elegant solution to this; just like using JNI to invoke C code from Java.  Any pointers? (FYI I'm v. new to Python)    Clarification (at the cost of a long question: apologies) The py app (which I don't own) takes user input in the form of a number of configuration files. It then interprits these and farms work off to a number of (hidden) tools via a plugin mechanism. I'm looking to add support for the functionality provided by the legacy Java app.  So it doesn't make sense to call the python app from the java app and I can't run the py app in a jython environment (on the JVM).  Since there is no obvious mechanism for this I think the simple CL invocation is the best solution.
79772
I'm trying to make a crossplatform C# application using C#, mono/GTK# on Linux and .NET/GTK# on Windows, however the startup sequence seems to need to be slightly different under the two platforms:  Under Linux:  public static void Main (string[] args) {     Gdk.Threads.Init ();     // etc...   Under Windows:  public static void Main (string[] args) {     Glib.Thread.Init ();     Gdk.Threads.Init ();     // etc...   Both require it to be done that way: Windows complains about g_thread_init() not being called with the linux code, and linux complains about it already being called with the Windows code. Other than this, it all works wonderfully.  My first attempt at a "solution" looked like:  public static void Main (string[] args) {     try {         Gdk.Threads.Init ();     } catch (Exception) {         GLib.Thread.Init ();         Gdk.Threads.Init ();     }     // etc...   But even this messy solution doesn't work; the error is coming from GTK+, unmanaged code, so it can't be caught. Does anyone have any bright ideas about the cause of the problem, and how to fix it? Or, failing that, have bright ideas on how to detect which one should be called at runtime?
99042
I am currently writing a little bootstrap code for a service that can be run in the console. It essentially boils down to calling the OnStart() method instead of using the ServiceBase to start and stop the service (because it doesn't run the application if it isn't installed as a service and makes debugging a nightmare).  Right now I am using Debugger.IsAttached to determine if I should use ServiceBase.Run or [service].OnStart, but I know that isn't the best idea because some times end users want to run the service in a console (to see the output etc. realtime).  Any ideas on how I could determine if the Windows service controller started 'me', or if the user started 'me' in the console? Apparantly  is not the answer. I thought about using commandline args, but that seems 'dirty'.  I could always see about a try-catch statement around ServiceBase.Run, but that seems dirty. Edit: Try catch doesn't work.  I have a solution: putting it up here for all the other interested stackers:      public void Run()     {         if (Debugger.IsAttached || Environment.GetCommandLineArgs().Contains&lt;string&gt;("-console"))         {             RunAllServices();         }         else         {             try             {                 string temp = Console.Title;                 ServiceBase.Run((ServiceBase[])ComponentsToRun);             }             catch             {                 RunAllServices();             }         }     } // void Run      private void RunAllServices()     {         foreach (ConsoleService component in ComponentsToRun)         {             component.Start();         }         WaitForCTRLC();         foreach (ConsoleService component in ComponentsToRun)         {             component.Stop();         }     }   EDIT: There was another question on StackOverflow where the guy had problems with the Environment.CurrentDirectory being "C:\Windows\System32" looks like that may be the answer. I will test today.
48887
Mainly I am looking for a way to pin an application to the Unity launch bar, and run it as root.  Currently, even if I start the application with sudo, and pin it after it starts, it will start as current user next time.  Sad, but there is no context menu option "run as ...".  Update: I switched to gnome3 and now I'm happy, I'm missing only the search.
24776
I need to spawn a child process that is a console application, and capture its output.  I wrote up the following code for a method:  string retMessage = String.Empty; ProcessStartInfo startInfo = new ProcessStartInfo(); Process p = new Process();  startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true;  startInfo.UseShellExecute = false; startInfo.Arguments = command; startInfo.FileName = exec;  p.StartInfo = startInfo; p.Start();  p.OutputDataReceived += new DataReceivedEventHandler (     delegate(object sender, DataReceivedEventArgs e)     {         using (StreamReader output = p.StandardOutput)         {             retMessage = output.ReadToEnd();         }     } );  p.WaitForExit();  return retMessage;   However, this does not return anything. I don't believe the OutputDataReceived event is being called back, or the WaitForExit() command may be blocking the thread so it will never callback.  Any advice?  EDIT: Looks like I was trying too hard with the callback. Doing:  return p.StandardOutput.ReadToEnd();    Appears to work fine.