----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

Hi,

Well thanks for the source code that will help greatly.  I have however
discoved what I beleive to be a (( BIG )) problem.  (not with you code, I
hasten to add....)

Runtime.getRuntime().exec("cd /tmp; mkdir ItWorked");

Reports the following error....

"IOException : cd : not found".

Now I know this is a big problem.  My current user setup in Apache is...

user : nobody
group : nogroup

Anymore Ideas out there?  Or am I doing something blindingly obvious?

Keith
---------------------------------------------------------------------------
Keith Ball - Praktikant
WA46 Operationelle  Analysen  Luftwaffe
IABG MbH       Einsteinstr. 20      85521 Ottobrunn
Phone : 0049-89-6088-2556
Email : [EMAIL PROTECTED]         WWW site : www.iabg.de
----------------------------------------------------------------------------

----- Original Message -----
From: Robert McGovern <[EMAIL PROTECTED]>
To: Java Apache Users <[EMAIL PROTECTED]>
Sent: Tuesday, February 22, 2000 11:12 AM
Subject: Re: Runtime.getRuntime().exec("mkdir
ISTILLhaveaproblem")............


> ----------------------------------------------------------------
> BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
> WHEN YOU POST, include all relevant version numbers, log files,
> and configuration files.  Don't make us guess your problem!!!
> ----------------------------------------------------------------
>
> Keith Ball wrote:
> >
> > > I am using a a servlet engine as a front end for RCS.  (Don't ask me I
just
> > prorgram here, I was thinking some nice swing front end, but I am not in
> > charge!)
>
> I have to admit I am doing the same thing. A Servlet front end to a CVS
> repository, that will check in and out projects.
>
> I have managed to get listing a directory, checking out a project and
> some other bits and pieces.
>
> Things you should bear in mind, ie what user is jserv running as? Will
> that person have permissions to create a directory in the desired
> location (for instance without specifying a directory you are working in
> the root directory).
>
> Rob
> ----------------
>
> Below is the source code for one file I am currently using to test the
> concept.
> If its easier I can mail it to you
>
>
> import java.io.*;
> import java.util.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class CVSProjectsCheckout extends HttpServlet {
>
> private BufferedReader in = null;
> private BufferedReader error = null;
> private String line = null;
>
> String username;
> String project;
> String directory;
>
> PrintWriter out = null;
>
> Runtime runtime = null;
>
> Process process = null;
>
> public void init(ServletConfig config) throws ServletException {
> super.init(config);
> runtime = Runtime.getRuntime();
> }
>
>
> public void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
>
> res.setContentType("text/html");
>
> out = res.getWriter();
>
> username = req.getRemoteUser();
> project = req.getParameter("project");
> directory = "test";
>
> String command2End = "cd ~/ ; mkdir " + directory;
> String command3End = "cd ~/ ; ls | grep -x " + directory;
> // String command4End = "cd ~/" + directory + " ; cvs checkout " +
> project;
> String command4End = "./tmp/checkout " + project;
> String command5End = "cd ~/ ; ls | grep -x " + username;
>
> String[] command = {"sudo", "-H", "-u", username, "/bin/csh", "-c",
> "cd ~/; pwd"}; file://works
> String[] command2 = {"sudo", "-H", "-u", username, "/bin/csh", "-c",
> command2End}; file://works
> String[] command3 = {"sudo", "-H", "-u", username, "/bin/csh", "-c",
> command3End}; file://works
> String[] command4 = {"sudo", "-H", "-u", username, "/bin/csh", "-c",
> command4End}; file://works
> String[] command5 = {"sudo", "-H", "-u", "robertm", "/bin/csh", "-c",
> command5End}; file://works
>
> out.println("Welcome " + username);
> out.println("<br><br>");
>
> out.println("Checking " + directory + " directory exists in you home
> area");
> out.println("<br><br>");
>
> boolean suc = false;
>
> if(checkForDirectory(command5) == true) {
>
> if(checkForDirectory(command3) == true) {
> suc = checkoutProject(command4);
> }
> else {
> if (makeDirectory(command2) == true) {
> suc = checkoutProject(command4);
> }
> }
>
> if(suc == true)

> out.println("Project checked out");
> }
> else {
> out.println("error checking project out");
> }
> }
> else {
> out.println("User " + username + " does not have a home directory.");
> out.println("<br><br>");
> out.println("Therefore the project will not be checked out");
> }
> }
>
> private boolean checkForDirectory(String[] command) throws IOException{
> try {
> if (command != null) {
> process = runtime.exec(command);
>
> in = new BufferedReader(new
> InputStreamReader(process.getInputStream()));
> error = new BufferedReader(new
> InputStreamReader(process.getErrorStream()));
>
> line = null;
>
> while((line = error.readLine()) != null) {
> out.println(line);
> }
>
> line = in.readLine();
>
> if (line != null) {
> in.close();
> error.close();
> out.println("Directory Exists");
> out.println("<br><br>");
> process.destroy();
> return true;
> }
> else {
> in.close();
> error.close();
> process.destroy();
> return false;
> }
> }
>
> } catch (Exception e) {
> out.println("Problem with 1" + e.toString());
>
> in.close();
> error.close();
> }
> process.destroy();
> return false;
> }
>
> private boolean checkoutProject(String[] command) throws IOException{
>
> boolean errorFlag = false;
>
> try {
> if (command != null) {
> out.println("Checking project out now");
> out.println("<br><br>");
>
> process = runtime.exec(command);
>
> in = new BufferedReader(new
> InputStreamReader(process.getInputStream()));
> error = new BufferedReader(new
> InputStreamReader(process.getErrorStream()));
>
> line = null;
>
> out.println("<pre>");
>
> while((line = in.readLine()) != null) {
> out.println(line);
> }
>
> while((line = error.readLine()) != null) {
> out.println(line);
> }
>
> process.waitFor();
>
> if (process.exitValue() != 0) {
> out.println("</pre>");
>
> in.close();
> error.close();
> process.destroy();
> return false;
> }
>
> out.println("</pre>");
>
> in.close();
> error.close();
> process.destroy();
> return true;
> }
>
>
> } catch (Exception e) {
> out.println("Problem with 2" + e.toString());
>
> in.close();
> error.close();
> }
> process.destroy();
> return false;
> }
>
> private boolean makeDirectory(String[] command) throws IOException {
> boolean errorFlag = false;
>
> try {
> if (command != null) {
> out.println("Making directory " + directory);
> out.println("<br><br>");
>
> process = runtime.exec(command);
>
> in = new BufferedReader(new
> InputStreamReader(process.getInputStream()));
> error = new BufferedReader(new
> InputStreamReader(process.getErrorStream()));
>
> line = null;
> while((line = error.readLine()) != null) {
> errorFlag = true;
> out.println(line);
> }
>
> if ( errorFlag == true) {
> in.close();
> error.close();
> process.destroy();
> return false;
> }
>
> while((line = in.readLine()) != null) {
> out.println(line);
> }
>
> in.close();
> error.close();
>
> out.println("Directory " + directory + " created");
> out.println("<br><br>");
> process.destroy();
> return true;
>
> }
>
> } catch (Exception e) {
> out.println("Problem with 3" + e.toString());
>
> in.close();
> error.close();
> }
> process.destroy();
>
> return false;
> }
> }
>
>
> --
> --------------------------------------------------------------
> Please read the FAQ! <http://java.apache.org/faq/>
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Archives and Other:  <http://java.apache.org/main/mail.html>
> Problems?:           [EMAIL PROTECTED]
>



--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to