C-Passing arguments for execution of a program in new Xterm window
<p><strong>Problem statement:-</strong></p>

<p>How to pass arguments to a program for execution in a new Xterm/Gnome window which will be calling through execlp.</p>

<p><strong>A little elaborate explanation:-</strong>(oxymoron eh?)</p>

<p>Consider the following program which will take a string as argument and display it</p>

<pre><code>//output.c
#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main(int argc, char *argv[])
{
    if(argc&lt;2)
        {
              printf("insufficient parameters\n");
              exit(1);
        }
    printf("%s",argv[1]);
    sleep(10);
    return 0;
</code></pre>

<p>}</p>

<p>And another program,<code>client.c</code>which, during the course of its execution is required to call <code>output.c</code> and make it display in a new xterm/gnome-terminal window.</p>

<pre><code>//client.c
int main()
{
    char buf[25]="Test String";//as argument for program to be called
    int pid_child=fork();
    if(pid_child==-1)
            {
                printf("Fork Failed. Exiting");
                exit(1);
            }

    if(pid_child==0)
            {   
            execlp("/usr/bin/xterm","-e","./output",buf,NULL);
            }

    int status=0;
    while(wait(&amp;status)!=-1);
}
</code></pre>

<p>The line of contention here is </p>

<pre><code>execlp("/usr/bin/xterm","-e","./output",buf,NULL); //With string `buf` as argument for `output`.
</code></pre>

<p>Result:-Does not run</p>

<blockquote>
  <p>Error
  -e: Explicit shell already was /~/cs60/directory/./output</p>
  
  <p>-e: bad command line option "Test String"</p>
</blockquote>

<pre><code>execlp("/usr/bin/xterm","-e","./output",NULL);//Without passing variable `buf` 
</code></pre>

<p>Result:-  a)  New Xterm window opens.   b) output terminates with Insufficient parameters (as expected).</p>

<p>The manpage clearly states for Xterm:</p>

<blockquote>
  <blockquote>
    <p>-e program [ arguments ... ] </p>
  </blockquote>

<pre><code>            This option specifies the program (and its command  line  arguments) to be run in the xterm window.
</code></pre>
</blockquote>

<p>It works perfectly fine when I run it from a terminal (as a script). But how can I achieve this through C.</p>

<p>Any help will be highly appreciated</p>