Re: g_spawn_asnyc -- What is wrong ?


 Thanks for the reply.

 you are right - remove() is ISO standard, but apparently broken on windows. It
seems that it is a call to unlink(), thus it fails when using on directories
((the only reason I know that is that GNU remove() man pages talks about it.
The other reason I cannot use remove() is that I will potentially get a path
such as  c:\mydir\*. In this case, I am supposed to delete the entire dicerctoy
recursively - which might be an expense operation from my single threaded app
if there are a lot of directories/files on it.

  As far as the changes you suggested, I added:
   char* cmd = "/bin/rm hello.txt";
   char** cmd1;
   int i = 0;
   if ( g_shell_parse_argv(cmd,&i, &cmd1, &err) != TRUE)
           g_print("Error parsing arg: %s\n", err->message);
           return 1;
   g_print("Number of args: %d\n", i);  /* this prints 2 as expected */

 but it still does not remove the file hello.txt from the current dir. I am
I am calling g_spawn the wrong way -- but where ?

  HELP :)

  Thanks again.

--- Tristan Van Berkom <vantr touchtunes com> wrote:

try using:
(that will just do the argv setup for you)

and remember that
      sprintf(text, "this and" "that");
will make text:
      "this andthat"
where as
      sprintf(text, "this and " "that");
will make:
      "this and that"

so your cmd is actualy:


instead of:

"/bin/rm hello.txt"

isn't "remove()" from stdio.h platform indepentend ?
(I'm not sure about opendir()/readdir() from dirent.h
but I think thats standard too.)

Harring Figueiredo wrote:

 Hello all,

 I am trying to use g_spawn_async, but so far I am not getting the results

  In the program below:
  1) The output from the func() is never displayed.
  2) The file hello.txt is never removed.
  3) I get the child's pid correctly (i.e, not 0 or -1)
  4) The program does not report errors.

   I am sure I am doing something really wrong -- where ?

  Note: I am trying to do this so that I can delete a directory recursively
windoze and Linux, so I am trying to stay platform independent by using
this -
Any better alternatives ?

   Thanks in advance.

=== Program ==========

void func(gpointer data) {
g_print("Executed child func ...");

int deltree(const char* path)
   char* cmd[] = { "/bin/rm" "hello.txt", "NULL"};
   gint pid = 0;
   GError* err = NULL;
   gboolean ret_val;
    GSpawnChildSetupFunc  func;

   ret_val = g_spawn_async_with_pipes(NULL,cmd ,NULL,
           &pid, NULL, NULL, NULL, &err);
   if(ret_val != TRUE)
       g_print("Did not fail.\n");

   if(err) g_print("Error: %s\n" , err->message);
   g_print("Child PID: %d\n" , pid);

   g_print (" Done...\n");
   return 0;

int main()
    return 0;

Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More

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