Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

widget.system() issues

Author Message
Drauchomyn



Joined: 14 Jul 2008
Posts: 3

Posted: Mon Jul 14, 2008 - 10:43 am    Post subject: widget.system() issues Reply with quote

I am having difficulty passing an argument to the widget.system() method.

The 'userInput' is a string containing parentheses.


Code:


function foo(){
  var str = document.getElementById('userInput').value

  //userInput is a string containing parentheses,
  //letters and numbers
  //want to replace the parentheses with curly brackets

  str = str.replace(/\050/g, "{");
  str = str.replace(/\051/g, "}");   
   
  return widget.system("program " + str, null).outputstring;

  //program is a C++ executable file which takes the   
  //parameter str and returns a float

}



The reason I want to replace the parentheses with curly brackets is because the bash terminal does not interpret the parentheses as literals, but does so with curly brackets.

When I try to run my widget, all I get for an answer is "undefined"; yet when I run my c++ executable in the terminal, it works fine with curly brackets.

Any help would be greatly appreciated.

Thanks!
View user's profile Send private message Send e-mail Widgets
Drauchomyn



Joined: 14 Jul 2008
Posts: 3

Posted: Mon Jul 14, 2008 - 11:19 am    Post subject: Reply with quote

Or, eqivalently, if I change the code to this:

Code:


function foo(){
  var str = document.getElementById('userInput').value

  str = str.replace(/\050/g, "\\(");
  str = str.replace(/\051/g, "\\)");   
   
  return widget.system("program " + str, null).outputstring;

}


So, then the terminal input should look like this, assuming the user input was (something):

Code:

program \(something\)


This works just fine when I run my c++ program in the terminal, but not when accessed through the widget.....I'm pretty puzzled as to to what's going on.
View user's profile Send private message Send e-mail Widgets
Drauchomyn



Joined: 14 Jul 2008
Posts: 3

Posted: Mon Jul 14, 2008 - 3:25 pm    Post subject: Reply with quote

The widget.system() error output message that I get is:

/bin/sh: myProgram: command not found


What does this mean and how do I fix it?
View user's profile Send private message Send e-mail Widgets
Quill



Joined: 23 Feb 2007
Posts: 11

Posted: Thu Jul 17, 2008 - 3:55 am    Post subject: "widget.system()" Errors Reply with quote

Are you allowing command line access in you Info.plist file?

Code:

<key>AllowSystem</key>
<true/>


If the application is outside of the widget bundle, you may also have to include:

Code:

<key>AllowFileAccessOutsideOfWidget</key>
<true/>


Quill
View user's profile Send private message Send e-mail Visit poster's website Widgets
thewilson



Joined: 28 Aug 2008
Posts: 18

Posted: Thu Aug 28, 2008 - 1:40 pm    Post subject: Re: widget.system() issues Reply with quote

Had some input on this snippet

Code:

  return widget.system("program " + str, null).outputstring;

  //program is a C++ executable file which takes the   
  //parameter str and returns a float


If you are using an external program to convert the string into a float you can use javascripts built in parseFloat() function. This will return the first float type number in the string. If you are manipulating the data in a c++ program and then returning a float number as a result there is another path to take.

parseFloat
http://www.w3schools.com/jsref/jsref_parseFloat.asp


If you are sending "program" a command line argument that includes spaces or you want it interpreted literally it must be enclosed in ' or " s.

IMHO should work fine

Code:

function foo(){
  var str = document.getElementById('userInput').value

  return widget.system("program " +  "'" + str + "'", null).outputstring;

}


this would go from value = "(something)" to program '(something)' and it will pass just fine.

If you are getting "undefined" as a result then you are not getting anything output to stdout you might see if widget.system("program " + "'" + str + "'", null).errorString;

And of course if I'm going to write this long as heck post I should also cover the make sure its plugged in possiblity.

Be certain that you are providing the absolute path to your program unless it is located in the same directory inside the widget bundle as the javascript that is being run.

Well thats it post #1 I am very excited about the possibilities the widget object has to offer and hope to be a productive member of this forum.

MW
View user's profile Send private message Send e-mail Widgets
thewilson



Joined: 28 Aug 2008
Posts: 18

Posted: Thu Aug 28, 2008 - 1:44 pm    Post subject: Reply with quote

Drauchomyn wrote:
The widget.system() error output message that I get is:

/bin/sh: myProgram: command not found


What does this mean and how do I fix it?


Ok I only read the first post before replying so I'm retarded ... touched ... special i dunno sorry for being dumb but anyway the solution is :

You need to put the full path to the program to be run if you dont know what it is go to the terminal and type the command 'pwd' to show you the current directory you are in and then put that in front of your command

pwd
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group