Shell - argv parameter with SPACE

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
 on mouseUp
   set the defaultFolder to "~/Desktop"
   
   /* ADD SPACES IN ARGUMENTS BY USING QUOTE */
   --put "One" into tFILE1
  // Below I added a space in the filename before the word copy.
   put quote & "/Users/JB/Desktop/SomeFile copy.jpg" & quote into tFILE1
   put "Two" into tFILE2
   put "Three" into tFILE3
   put "Four" into tFILE4
   put shell( "./argv_c++" && tFILE1 && tFILE2 && tFILE3 && tFILE4) into pData
   put pData into fld id <YOURFIELD>
   beep 2
end mouseUp
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
JB, a few of these snippets have been posted to the list, but with no
explanatory text.  Were these intended for someone else?

If you meant to send them here, for the benefit of those of us who may
not have ready access to an Objective-C compiler, would you mind
offering some description of what we should be learning from these?

--
  Richard Gaskin
  Fourth World Systems


JB wrote:


> Compile the following objective-c code as argv_nsstring-1
>
> #import <Foundation/Foundation.h>
>
> int main(int argc, const char * argv[]) {
>     @autoreleasepool {
>         NSString *arg1 = [NSString stringWithUTF8String:argv[1]];
>         NSString *arg2 = [NSString stringWithUTF8String:argv[2]];
>         NSString *arg3 = [NSString stringWithUTF8String:argv[3]];
>         NSLog(@"\nArgument 1: %@\n", arg1);
>         NSLog(@"\nArgument 2: %@\n", arg2);
>         NSLog(@"\nArgument 3: %@\n", arg3);
>     }
>
>     return 0;
> }
>
>
> Enter the following code in a button;
>
> on mouseUp
>    set the defaultFolder to "~/Desktop"
>    put "ONE TWO THREE" into tFILE
>    put shell( "./argv_nsstring-1" && tFILE) into pData
>    put pData into fld id <YOURFIELD>
>    beep 2
> end mouseUp




> ompile the following C++ code as argv_c++
>
> #include <iostream>
>
> // When passing char arrays as parameters they must be pointers
> int main(int argc, char* argv[]) {
>     if (argc < 5) { // Check the value of argc. If not enough parameters have been passed, inform user and exit.
>         std::cout << "Usage: Enter 4 Arguments & try again.\n"; // Inform the user of how to use the program
>         exit(0);
>
>     } else { // if we got enough parameters...
>         std::cout << argv[0] << "\n";
>         for (int i = 1; i < argc; i++) { /* We will iterate over argv[] to get the parameters stored inside.
>                                           * Note that we're starting on 1 because we don't need to know the
>                                           * path of the program, which is stored in argv[0] */
>
>             std::cout << argv[i] << "\n";
>         }
>
>         return 0;
>     }
> }
>
>
> Enter the following code in a button;
>
> on mouseUp
>    set the defaultFolder to "/Users/JB/Desktop/"
>
>    /* DO NOT USE ANY SPACES IN ARGUMENTS */
>    put "One" into tFILE1
>    put "Two" into tFILE2
>    put "Three" into tFILE3
>    put "Four" into tFILE4
>    put shell( "./argv_c++" && tFILE1 && tFILE2 && tFILE3 && tFILE4) into pData
>    put pData into fld id 342435
>    beep 2
> end mouseUp




>  on mouseUp
>    set the defaultFolder to "~/Desktop"
>
>    /* ADD SPACES IN ARGUMENTS BY USING QUOTE */
>    --put "One" into tFILE1
>   // Below I added a space in the filename before the word copy.
>    put quote & "/Users/JB/Desktop/SomeFile copy.jpg" & quote into tFILE1
>    put "Two" into tFILE2
>    put "Three" into tFILE3
>    put "Four" into tFILE4
>    put shell( "./argv_c++" && tFILE1 && tFILE2 && tFILE3 && tFILE4) into pData
>    put pData into fld id <YOURFIELD>
>    beep 2
> end mouseUp

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
Hi Richard,

There are plenty of free compilers.  Xcode will
compile c, c++, and objective-c.  To compile
from the terminal you can use gcc which is a
really good compiler.

What the code provided does it it gives you the
ability to use c, c++, objective-c, and Java code
in your Livecode stacks.

For those who have a basic understanding of any
of these languages there is a lot of code on the
web they can use with little of no changes giving
them a lot of extra power with little effort.

These examples are the MAIN LINK to using other
code within Livecode.

I understand a lot of people do not know or want to
know other languages and this code is aimed at the
few people who do now or will in the future.

Providing this ability can attract programmers who do
not use Livecode now but know other languages and
want to use their knowledge with Livecode.

JB


> On Jun 24, 2017, at 7:50 PM, Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> JB, a few of these snippets have been posted to the list, but with no explanatory text.  Were these intended for someone else?
>
> If you meant to send them here, for the benefit of those of us who may not have ready access to an Objective-C compiler, would you mind offering some description of what we should be learning from these?
>
> --
> Richard Gaskin
> Fourth World Systems
>
>
> JB wrote:
>
>
>> Compile the following objective-c code as argv_nsstring-1
>>
>> #import <Foundation/Foundation.h>
>>
>> int main(int argc, const char * argv[]) {
>>    @autoreleasepool {
>>        NSString *arg1 = [NSString stringWithUTF8String:argv[1]];
>>        NSString *arg2 = [NSString stringWithUTF8String:argv[2]];
>>        NSString *arg3 = [NSString stringWithUTF8String:argv[3]];
>>        NSLog(@"\nArgument 1: %@\n", arg1);
>>        NSLog(@"\nArgument 2: %@\n", arg2);
>>        NSLog(@"\nArgument 3: %@\n", arg3);
>>    }
>>
>>    return 0;
>> }
>>
>>
>> Enter the following code in a button;
>>
>> on mouseUp
>>   set the defaultFolder to "~/Desktop"
>>   put "ONE TWO THREE" into tFILE
>>   put shell( "./argv_nsstring-1" && tFILE) into pData
>>   put pData into fld id <YOURFIELD>
>>   beep 2
>> end mouseUp
>
>
>
>
>> ompile the following C++ code as argv_c++
>>
>> #include <iostream>
>>
>> // When passing char arrays as parameters they must be pointers
>> int main(int argc, char* argv[]) {
>>    if (argc < 5) { // Check the value of argc. If not enough parameters have been passed, inform user and exit.
>>        std::cout << "Usage: Enter 4 Arguments & try again.\n"; // Inform the user of how to use the program
>>        exit(0);
>>
>>    } else { // if we got enough parameters...
>>        std::cout << argv[0] << "\n";
>>        for (int i = 1; i < argc; i++) { /* We will iterate over argv[] to get the parameters stored inside.
>>                                          * Note that we're starting on 1 because we don't need to know the
>>                                          * path of the program, which is stored in argv[0] */
>>
>>            std::cout << argv[i] << "\n";
>>        }
>>
>>        return 0;
>>    }
>> }
>>
>>
>> Enter the following code in a button;
>>
>> on mouseUp
>>   set the defaultFolder to "/Users/JB/Desktop/"
>>
>>   /* DO NOT USE ANY SPACES IN ARGUMENTS */
>>   put "One" into tFILE1
>>   put "Two" into tFILE2
>>   put "Three" into tFILE3
>>   put "Four" into tFILE4
>>   put shell( "./argv_c++" && tFILE1 && tFILE2 && tFILE3 && tFILE4) into pData
>>   put pData into fld id 342435
>>   beep 2
>> end mouseUp
>
>
>
>
>> on mouseUp
>>   set the defaultFolder to "~/Desktop"
>>
>>   /* ADD SPACES IN ARGUMENTS BY USING QUOTE */
>>   --put "One" into tFILE1
>>  // Below I added a space in the filename before the word copy.
>>   put quote & "/Users/JB/Desktop/SomeFile copy.jpg" & quote into tFILE1
>>   put "Two" into tFILE2
>>   put "Three" into tFILE3
>>   put "Four" into tFILE4
>>   put shell( "./argv_c++" && tFILE1 && tFILE2 && tFILE3 && tFILE4) into pData
>>   put pData into fld id <YOURFIELD>
>>   beep 2
>> end mouseUp
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
JB wrote:
...

> What the code provided does it it gives you the
> ability to use c, c++, objective-c, and Java code
> in your Livecode stacks.
>
> For those who have a basic understanding of any
> of these languages there is a lot of code on the
> web they can use with little of no changes giving
> them a lot of extra power with little effort.
>
> These examples are the MAIN LINK to using other
> code within Livecode.
>
> I understand a lot of people do not know or want to
> know other languages and this code is aimed at the
> few people who do now or will in the future.
>
> Providing this ability can attract programmers who do
> not use Livecode now but know other languages and
> want to use their knowledge with Livecode.

Ah, thanks.

Yes, the shell function is very handy.

In addition to calling compiled code, you can also call
platform-independent scripts from it as well, like Python, bash, perl, etc.

"open process" can also be useful, with some additional options shell
doesn't offer.

And for deep, efficient integration there's also LC's External API
(though I don't know where that's documented these days - Mark Wieder,
do you know where we can find the docs and templates for that?)

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
I really did not use the shell command before I started posting
the c and java code.

I was starting to learn Python and would love to know hoe to
use the shell to integrate it into Livecode stacks.

In fact I would love any shell examples!

JB


> On Jun 24, 2017, at 8:25 PM, Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> JB wrote:
> ..
>> What the code provided does it it gives you the
>> ability to use c, c++, objective-c, and Java code
>> in your Livecode stacks.
>>
>> For those who have a basic understanding of any
>> of these languages there is a lot of code on the
>> web they can use with little of no changes giving
>> them a lot of extra power with little effort.
>>
>> These examples are the MAIN LINK to using other
>> code within Livecode.
>>
>> I understand a lot of people do not know or want to
>> know other languages and this code is aimed at the
>> few people who do now or will in the future.
>>
>> Providing this ability can attract programmers who do
>> not use Livecode now but know other languages and
>> want to use their knowledge with Livecode.
>
> Ah, thanks.
>
> Yes, the shell function is very handy.
>
> In addition to calling compiled code, you can also call platform-independent scripts from it as well, like Python, bash, perl, etc.
>
> "open process" can also be useful, with some additional options shell doesn't offer.
>
> And for deep, efficient integration there's also LC's External API (though I don't know where that's documented these days - Mark Wieder, do you know where we can find the docs and templates for that?)
>
> --
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web
> ____________________________________________________________________
> [hidden email]                http://www.FourthWorld.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
JB wrote:
> I really did not use the shell command before I started posting
> the c and java code.
>
> I was starting to learn Python and would love to know hoe to
> use the shell to integrate it into Livecode stacks.
>
> In fact I would love any shell examples!

Here's a quickie off the top of my head (read "Don't sue me if it needs
tweaking to work" <g>) for using rsync to back up a local folder to a
folder on a remote server.

on mouseUp
    put fld "SourceDir" into tSrc
    put fld "DestDir" into tDest
    put fld "User" into tUser
    put fld "Server" into tServer
    put fld "PortNumber" into tPort
    if tPort is not empty then put "-p " before tPort
    --
    put "rsync -az "& tPort &&quote& tSrc &quote \
          &&quote& tUser &"@" & tServer & ":" & \
          tDest &quote into tCmd
    put shell(tCmd)
end mouseUp


Note: LC's shell function isn't interactive of course, so you'll want to
set up a shared SSH key on the server first for passwordless login.

If you haven't done it before you'll be glad you did, and even more glad
when you've tested that it works well so you can turn off password login
altogether (ah, such slender auth.logs after that <g>).

This is a good guide on setting up shared SSH keys:
<https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2>

If you need to handle passwords or other interactions in shell, I don't
know of a platform-indendent way to do that.  But in Linux (and maybe
Mac if you install via Homebrew) you can use Expect.

Here are some examples of using Expect with bash:
<http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts>

I had started down the road of making a server management toolkit in LC
a while back, but time's hard to come by so I'll likely be using Ansible
for that soon.  If I can turn up any of my LC experiments mixing bash
and Expect in shell calls I'll post 'em.

Like most uses of shell, it's just like using the command line but with
a lot of confusing concatenation. :)

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
THANK YOU!

JB


> On Jun 24, 2017, at 9:05 PM, Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> JB wrote:
>> I really did not use the shell command before I started posting
>> the c and java code.
>>
>> I was starting to learn Python and would love to know hoe to
>> use the shell to integrate it into Livecode stacks.
>>
>> In fact I would love any shell examples!
>
> Here's a quickie off the top of my head (read "Don't sue me if it needs tweaking to work" <g>) for using rsync to back up a local folder to a folder on a remote server.
>
> on mouseUp
>   put fld "SourceDir" into tSrc
>   put fld "DestDir" into tDest
>   put fld "User" into tUser
>   put fld "Server" into tServer
>   put fld "PortNumber" into tPort
>   if tPort is not empty then put "-p " before tPort
>   --
>   put "rsync -az "& tPort &&quote& tSrc &quote \
>         &&quote& tUser &"@" & tServer & ":" & \
>         tDest &quote into tCmd
>   put shell(tCmd)
> end mouseUp
>
>
> Note: LC's shell function isn't interactive of course, so you'll want to set up a shared SSH key on the server first for passwordless login.
>
> If you haven't done it before you'll be glad you did, and even more glad when you've tested that it works well so you can turn off password login altogether (ah, such slender auth.logs after that <g>).
>
> This is a good guide on setting up shared SSH keys:
> <https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2>
>
> If you need to handle passwords or other interactions in shell, I don't know of a platform-indendent way to do that.  But in Linux (and maybe Mac if you install via Homebrew) you can use Expect.
>
> Here are some examples of using Expect with bash:
> <http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts>
>
> I had started down the road of making a server management toolkit in LC a while back, but time's hard to come by so I'll likely be using Ansible for that soon.  If I can turn up any of my LC experiments mixing bash and Expect in shell calls I'll post 'em.
>
> Like most uses of shell, it's just like using the command line but with a lot of confusing concatenation. :)
>
> --
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web
> ____________________________________________________________________
> [hidden email]                http://www.FourthWorld.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell - argv parameter with SPACE

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
On 25 June 2017 at 04:12, JB via use-livecode <[hidden email]
> wrote:

> What the code provided does it it gives you the
> ability to use c, c++, objective-c, and Java code
> in your Livecode stacks.
>

This is really useful. Thanks JB

Sean Cole
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...