Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3881

Beginners • Re: Terminal window opening

$
0
0
Basic question- I am working on a C program for the RP4. When executed from inside the Geany IDE, or from a command line, a terminal window is automatically started. This is very useful for debugging via printf() statements. When the program is executed normally (autostarted from a crontab entry) no terminal appears. So far I can't find how to open up a terminal from inside the program after it is launched. Any suggestions would be appreciated.
At a guess... When you run the program in the IDE, it opens a terminal session for an stdout/stderr output. When you run from a terminal session, that is the stdout/stderr location. (printf() writes to stdout. If you want to write to a specific file--stdout, staderr or something else, use fopen() and fprinf() below is my convention for setting up a log file for any of my own error messages...)

Code:

/*  Create and open log file    */   sprintf(my_pid, "%d", getpid());   strcpy(logfile, "/home/ddcadmin/log/");   strcat(logfile, argv[0]);   strcat(logfile, "_");   strcat(logfile, my_pid);   strcat(logfile, ".log");   log_file = fopen(logfile,"w");   if(log_file == NULL)   {      fprintf(stderr,"Log file %s open failed. Quiting.\n", logfile);      exit(-1);   }   printf("Diag:  Log file should exist.\n");   fprintf(log_file,"Starting program ddc.c\n");

Statistics: Posted by W. H. Heydt — Fri May 17, 2024 1:07 am



Viewing all articles
Browse latest Browse all 3881

Trending Articles