Advertisement
Hey all,
I am creating a service that opens a specialized shell and keeps track of that process by entering it into a hashtable. The initialization uses a checkForPrompt function that searches the InputStreams for a special character, ie '$' or ']'. However when I start the process on Linux, no prompt appears. (Ironically this works on Windows.) A snippet of my code:
Process ps = null;
InputStream in, err;
exec = "bash";
try
{
ps = m_runtime.exec(exec);
in = ps.getInputStream();
err = ps.getErrorStream();
while(!timeout){
tmpIn = readFromStream( in, "in" );
if(checkForPrompt(tmpIn))
return true;
}
else
timeout++;
}
.
.
.
Will the process ever return a prompt? Is there a better way to do this or check to see if the shell has been entered?
Thanks!
Cecilia
I am creating a service that opens a specialized shell and keeps track of that process by entering it into a hashtable. The initialization uses a checkForPrompt function that searches the InputStreams for a special character, ie '$' or ']'. However when I start the process on Linux, no prompt appears. (Ironically this works on Windows.) A snippet of my code:
Process ps = null;
InputStream in, err;
exec = "bash";
try
{
ps = m_runtime.exec(exec);
in = ps.getInputStream();
err = ps.getErrorStream();
while(!timeout){
tmpIn = readFromStream( in, "in" );
if(checkForPrompt(tmpIn))
return true;
}
else
timeout++;
}
.
.
.
Will the process ever return a prompt? Is there a better way to do this or check to see if the shell has been entered?
Thanks!
Cecilia
Advertisement
Advertisement
-
Unsu...
Re: trying to open a shell using Runtime.exec()
Fri, July 29, 2005 - 3:31 PMHave you tried printing out tmpIn to see what's actually being returned? That might help you debug.... -
-
Unsu...
Re: trying to open a shell using Runtime.exec()
Fri, July 29, 2005 - 3:32 PMHave you tried step debugging?
-
Re: trying to open a shell using Runtime.exec()
Fri, July 29, 2005 - 4:23 PMThe exec() call works; a shell is created. However there is no prompt, so it is a blank line. I can run commands (for example, 'ls /usr') in this shell after the Runtime.exec("bash"), but there is no consistent ending characteristic of the commands that I'm running in order to create an effective checkForPrompt. -
-
Re: trying to open a shell using Runtime.exec()
Fri, July 29, 2005 - 4:24 PMsorry, I meant to say that tmpIn is a blank line when running Runtime.exec("bash").
-
-
-
Re: trying to open a shell using Runtime.exec()
Fri, July 29, 2005 - 5:45 PMDid you try running "bash -i", to start bash in interactive mode?