Re: g_spawn and files left locked on windows.



On Mon, 2009-04-27 at 12:52 +0300, Tor Lillqvist wrote:
My application invokes the lilypond program using the g_spawn...
functions. This works fine on linux, but on windows the files created by
lilypond are left locked when lilypond has exited.

That sounds very odd and in fact impossible. Are you confusing file
protection with locking?
Thank you for the quick and helpful reply. Having contstructed the
minimal example, everything worked fine. 
For those listening in who need to create a glib standalone minimal
example. I append the code I devised.
Richard
/************ first program, invoked by the one below *************/
#include <stdio.h>

/*
program doit
 gcc test.c -o doit.exe
*/
int main(void) {
  printf("Opening the test file now\n");
  FILE *fp = fopen("thetestfile","w");
  if(fp==NULL) {
  printf("doit could not open the test file");
  return -1;
  }
  printf("Writing to the test file now\n");
  fprintf(fp, "hello");
  fclose(fp);
  return 0;
}

/****************** second program, invoking the first *********************/

/*
program test
 gcc  test.c -o test.exe -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include  /usr/lib/libglib-2.0.so
*/
#include <stdio.h>
#include <glib.h>
static GPid pid = -1;
void finished(void) {
  g_spawn_close_pid (pid);
  FILE *fp = fopen("thetestfile","rw");
  if(fp==NULL) {
    g_print("could not open\n");
    exit(-1);
  }
  g_print("The file opens ok\n");
  exit(0);
}

int main(void) {
  g_print("Starting the test\n");
  gchar *arguments[] = {
    "doit.exe",
    NULL
  };
  g_spawn_async_with_pipes (NULL,               /* dir */
                arguments, NULL,        /* env */
                G_SPAWN_SEARCH_PATH  | G_SPAWN_DO_NOT_REAP_CHILD, NULL, /* child setup func */
                NULL,           /* user data */
                &pid,
                NULL,
                NULL,           /* stdout */
                NULL,           /* stderr */
                NULL);
 g_child_watch_add (pid, (GChildWatchFunc)finished, NULL);
 g_print("looping for ever, Ctrl-C to kill\n");
 GMainLoop* gm = g_main_loop_new(NULL, 0);
 g_main_loop_run(gm);
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]