Re: g_spawn_asnyc -- What is wrong ?



 Folk,

 I discovery something intersting. If I call g_spawn_async_with_pipes(...) with
the callback func argument, the it does not work, but if I pass NULL to it, it
works.

cmd= "/bin/rm hello.txt";
g_spawn_async_with_pipes(NULL,cmd ,NULL,
          G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_SEARCH_PATH, func,
NULL,&pid, NULL, NULL, NULL, &err) will not fail, but the hello.txt does not
get removed.

With:
g_spawn_async_with_pipes(NULL,cmd ,NULL,
          G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_SEARCH_PATH, NULL,NULL,
          &pid, NULL, NULL, NULL, &err);  the hello.txt file gets removed.




--- Harring Figueiredo <harringf yahoo com> wrote:

  Tristan,

 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
sure
I am calling g_spawn the wrong way -- but where ?


  HELP :)

  Thanks again.
Harring


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

try using:
    g_shell_parse_argv()
(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:

"/bin/rmhello.txt"

instead of:

"/bin/rm hello.txt"

BTW:
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
I
expect.

  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
in
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,
           G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_SEARCH_PATH, func,
NULL,
           &pid, NULL, NULL, NULL, &err);
   if(ret_val != TRUE)
       g_print("Failed..\n");
   else
       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()
{
    deltree("path");
    return 0;
}

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com



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