[Project_owners] run Shell Script on Mac with nsIProcess

Gary Johnson gary.johnson.53 at gmail.com
Fri Sep 7 06:50:25 PDT 2007


> Did you try to troubleshout your code a bit ?
I have been working on this off on on for a week.  I bought a mac mini
so I could troubleshoot the MAC release of my extension.

> Is the gjtemp.sh file created after your have run your code ?
> Does FF have authority to write a file in that location ?
> Does FF have authority to create a .out file in that location ?
Please see the line.

I create the file gjtemp.sh fine.  Since I create a file there, I
think that answers your other questions.

---------------------
I am prone to asking questions when RTFM will do the job, but in this
case, I am stumped.
My first program was written in Fortran on an IBM 360.  I used an
Apple II and an Apple Lisa but I have not worked on MACs since the
LISA.  When I first used the cygwin shell to compile Mozilla, I wrote
a few scripts.  I could not get them to run and was confused.  Then a
friend said, Gary, you have to put a period and a space in front of
them.  So I thought I would ask for help again.


On 9/6/07, Didier Ernotte <didier at ernotte.com> wrote:
> Did you try to troubleshout your code a bit ?
> Is the gjtemp.sh file created after your have run your code ?
> Does FF have authority to write a file in that location ?
> Does FF have authority to create a .out file in that location ?
>
> Didier
>
>
>
>
> Gary Johnson <gary.johnson.53 at gmail.com> wrote:
>  /*
> I need to unzip files that have characters that FF does not currently
> support
> I am looking at using unix commands to do my work
> I am trying to get a shell process to run with nsIProcess on MAC OS 10
> with no luck
> I create the file gjtemp.sh fine
>
> */
>
> function runShelScriptonMac(what)
> {
> // get path to my extensions temp directory created during install
> // any existing directory will do
>  var sstrpart1 = getFFpath('ProfD')
>  var sstrpart2 =
> '/extensions/{2ea91495-764f-44ab-9639-dcb810fa1b43}/temp';
>
> // create a Moz file obj to that path
>
>  var zipdir = Components.classes["@mozilla.org/file/local;1"]
>  .createInstance(Components.interfaces.nsILocalFile);
>
>  Components.utils.reportError("the path " + sstrpart1 + sstrpart2);
>  zipdir.initWithPath( sstrpart1 + sstrpart2 );
>
> // create a file for Mac script comands
>  var scriptfile = zipdir.clone();
>
>  scriptfile.append("gjtemp.sh");
>
> // you have to write to it
>
>  var fos =
> Components.classes["@mozilla.org/network/file-output-stream;1"]
> .createInstance(Components.interfaces.nsIFileOutputStream);
>  fos.init(scriptfile, -1, -1, false);
>
> // shell commands are supposed to start with this
>
>  var line = '#!/bin/sh' + "\n";
>
> // set up a change directory line in the script file to make sure I
> end up in my temp dir
>
>  line += "cd ";
>
>  line += "/p ";
>
>  line += "\"" + zipdir.path + "\"\n";
>
>  fos.write(line, line.length);
>
> // run a test command and write results to a file called test1.out
>  line = "set > test1.out";
>
>  line += "\n";
>  fos.write(line, line.length);
>  fos.close();
>
>
>  Components.utils.reportError("the command " + line);
>
> // Get an nsIProcess
>
>  var process = Components.classes["@mozilla.org/process/util;1"]
>  .createInstance(Components.interfaces.nsIProcess);
>
> // Create a file obj for the shell
>
>  var sh = Components.classes["@mozilla.org/file/local;1"]
>  .createInstance(Components.interfaces.nsILocalFile);
>
>  sh.initWithPath("/bin/sh");
>
>  process.init(sh);
> // process.init(scriptfile); //this is what you do on windows
>
>  var args = [scriptfile.path];
>
>  Components.utils.reportError(args);
>
>
>  try
>  {
>  process.run(true, args, args.length);
>  }
>  catch (err)
>  {
>  Components.utils.reportError(err);
>  }
>
> // where are my results? I must be doing something wrong
> }
>
> /*
> String Meaning
> ProfD profile directory
> */
>
> function getFFpath(what)
> {
>  try
>  {
>
>
>
> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
>  // get profile directory
>  var myfileobj =
> Components.classes["@mozilla.org/file/directory_service;1"]
>  .getService(Components.interfaces.nsIProperties)
>  .get(what, Components.interfaces.nsIFile);
>
>  return(myfileobj.path);
>  }
>  catch(err)
>  {
>  Components.utils.reportError(err);
>  }
> return false;
> }
>
> --
> I hope to be the kind of person my dog thinks I am. :)>
>
> http://mywebpages.comcast.net/adgj/
> http://wwwCookDotCom.com
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>


-- 
I hope to be the kind of person my dog thinks I am.   :)>

http://mywebpages.comcast.net/adgj/
http://wwwCookDotCom.com


More information about the Project_owners mailing list