Shell argv

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Shell argv

Bob Sneidar via use-livecode
To use a shell command it needs to work from
the terminal.  I am using OS X  10.11.6 and if
I try to open a Xcode c build named my_file I
type in the terminal,

open my_file

and the file my_file will open.

I want to pass arguments to argv but the never
get passed.  I have tried the following;

open my_file —args arg1

The argument never gets passed.  Does anyone
know how to pass arguments to argv from the
terminal when open a file so I can use the script
from a shell command?

JB




_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
try man open in the terminal. That should tell you what the arguments to the open command are.

Bob S


> On May 6, 2017, at 18:46 , JB via use-livecode <[hidden email]> wrote:
>
> To use a shell command it needs to work from
> the terminal.  I am using OS X  10.11.6 and if
> I try to open a Xcode c build named my_file I
> type in the terminal,
>
> open my_file
>
> and the file my_file will open.
>
> I want to pass arguments to argv but the never
> get passed.  I have tried the following;
>
> open my_file —args arg1
>
> The argument never gets passed.  Does anyone
> know how to pass arguments to argv from the
> terminal when open a file so I can use the script
> from a shell command?
>
> JB
>
>
>
>
> _______________________________________________
> 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
|

Re: Shell argv

Bob Sneidar via use-livecode
Thanks Bob.

I did that before I sent the message and searched
a lot on the web.  It looks to me like I am entering
everything properly.  I will not that the file takes a
full path and I did not show a full path but I always
used a full path.  Maybe I will try compiling with
gcc sometime to see if that works.

JB


> On May 8, 2017, at 8:32 AM, Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> try man open in the terminal. That should tell you what the arguments to the open command are.
>
> Bob S
>
>
>> On May 6, 2017, at 18:46 , JB via use-livecode <[hidden email]> wrote:
>>
>> To use a shell command it needs to work from
>> the terminal.  I am using OS X  10.11.6 and if
>> I try to open a Xcode c build named my_file I
>> type in the terminal,
>>
>> open my_file
>>
>> and the file my_file will open.
>>
>> I want to pass arguments to argv but the never
>> get passed.  I have tried the following;
>>
>> open my_file —args arg1
>>
>> The argument never gets passed.  Does anyone
>> know how to pass arguments to argv from the
>> terminal when open a file so I can use the script
>> from a shell command?
>>
>> JB
>>
>>
>>
>>
>> _______________________________________________
>> 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


_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
In reply to this post by Bob Sneidar via use-livecode
On 2017-05-07 03:46, JB via use-livecode wrote:
> To use a shell command it needs to work from
> the terminal.  I am using OS X  10.11.6 and if
> I try to open a Xcode c build named my_file I
> type in the terminal,
>
> open my_file
>
> and the file my_file will open.

What is 'my_file'?

The terminal command 'open' looks at the filename, works out what app it
should be opened by and then launches the file in that app.

For example:

   open foo.c

Will open 'foo.c' (as a editable text file) in Xcode on my machine.

The '--args' portion of the open command allows you to pass extra
arguments to the application which is chosen to open the file.

> The argument never gets passed.  Does anyone
> know how to pass arguments to argv from the
> terminal when open a file so I can use the script
> from a shell command?

What exactly are you trying to do?

Warmest Regards,

Mark.

--
Mark Waddingham ~ [hidden email] ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
Hi Mark,

Thanks for the reply and info.

The file is actually named Hello and it is
a c program compiled with xcode.

It takes the argc value and if it is less than 2
returns a message a parameter was not added.
If it is 2 then it prints the value of argv[1] which
would be the first argument passed by the info
I give when opening the file.  After that no matter
what value argc is it prints the value of argv[0]
and that is always the name and path of the file.

The file executes properly and the message is printed
showing I did not enter any arguments even though I
did try to and then it prints the file name and path like
I told it to from argv[0].

JB
 

_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
In reply to this post by Bob Sneidar via use-livecode
Here is the code;

#include<stdio.h>

int main (int argc, char *argv[])
{
    if (argc < 2)
        printf ("You didn't enter any arguments.\n");
    else
        printf ("Your argument at position 1 is: %s\n", argv[1]);
   
    printf ("\nYour file path is:\n%s\n\n", argv[0]);
   
    return 0;
}

JB

_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
In reply to this post by Bob Sneidar via use-livecode
On 05/08/2017 10:36 AM, JB via use-livecode wrote:

> The file executes properly and the message is printed
> showing I did not enter any arguments even though I
> did try to and then it prints the file name and path like
> I told it to from argv[0].
>
> JB

In your original post you said "-args". The correct syntax is "--args"
(with two dashes rather than one), so if that's not a typo in your
original email, try correcting that and see what happens.

--
  Mark Wieder
  [hidden email]

_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
That is a typo.

In fact I tried every way and every
place within the open script and if
it is written different the code is not
executed and I get and error.

JB


> On May 8, 2017, at 10:57 AM, Mark Wieder via use-livecode <[hidden email]> wrote:
>
> On 05/08/2017 10:36 AM, JB via use-livecode wrote:
>
>> The file executes properly and the message is printed
>> showing I did not enter any arguments even though I
>> did try to and then it prints the file name and path like
>> I told it to from argv[0].
>>
>> JB
>
> In your original post you said "-args". The correct syntax is "--args" (with two dashes rather than one), so if that's not a typo in your original email, try correcting that and see what happens.
>
> --
> Mark Wieder
> [hidden email]
>
> _______________________________________________
> 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
|

Re: Shell argv

Bob Sneidar via use-livecode
Seems to me, if its the compiled version, you shouldn't need to use "open"
at all.

a simple
get shell("path/to/executable argument1 argument2")
If I understand what I read about "open" enough, it expects a file, that
will be opened in another app, like in Marks example.  (whatever.c opens
xcode)

If you want to experiment with open, you could try the following..

open -a /path/to/your/app /path/to/a/dummy/file/to/open --args arg1 arg2

I'm guessing that if you can format this right, it'll report the name of
the dummy file, and arg1 and arg2 as you expect.

But since you just want to pass arguments to your compiled program, I am
pretty sure you just need to use shell() and call it directly with the
arguments as part of the call.


On Mon, May 8, 2017 at 12:05 PM, JB via use-livecode <
[hidden email]> wrote:

> That is a typo.
>
> In fact I tried every way and every
> place within the open script and if
> it is written different the code is not
> executed and I get and error.
>
> JB
>
>
> > On May 8, 2017, at 10:57 AM, Mark Wieder via use-livecode <
> [hidden email]> wrote:
> >
> > On 05/08/2017 10:36 AM, JB via use-livecode wrote:
> >
> >> The file executes properly and the message is printed
> >> showing I did not enter any arguments even though I
> >> did try to and then it prints the file name and path like
> >> I told it to from argv[0].
> >>
> >> JB
> >
> > In your original post you said "-args". The correct syntax is "--args"
> (with two dashes rather than one), so if that's not a typo in your original
> email, try correcting that and see what happens.
> >
> > --
> > Mark Wieder
> > [hidden email]
> >
> > _______________________________________________
> > 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
>
_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
Hi Mike,

Thank you for the info.

The dictionary for Shell states it needs to work
from the Terminal to work correctly with Shell so
I have been doing everything from the Terminal at
this point.  I was trying to figure out how to write
it properly in the Terminal so I could use similar
code with the Shell.

JB


> On May 8, 2017, at 11:45 AM, Mike Bonner via use-livecode <[hidden email]> wrote:
>
> Seems to me, if its the compiled version, you shouldn't need to use "open"
> at all.
>
> a simple
> get shell("path/to/executable argument1 argument2")
> If I understand what I read about "open" enough, it expects a file, that
> will be opened in another app, like in Marks example.  (whatever.c opens
> xcode)
>
> If you want to experiment with open, you could try the following..
>
> open -a /path/to/your/app /path/to/a/dummy/file/to/open --args arg1 arg2
>
> I'm guessing that if you can format this right, it'll report the name of
> the dummy file, and arg1 and arg2 as you expect.
>
> But since you just want to pass arguments to your compiled program, I am
> pretty sure you just need to use shell() and call it directly with the
> arguments as part of the call.
>
>
> On Mon, May 8, 2017 at 12:05 PM, JB via use-livecode <
> [hidden email]> wrote:
>
>> That is a typo.
>>
>> In fact I tried every way and every
>> place within the open script and if
>> it is written different the code is not
>> executed and I get and error.
>>
>> JB
>>
>>
>>> On May 8, 2017, at 10:57 AM, Mark Wieder via use-livecode <
>> [hidden email]> wrote:
>>>
>>> On 05/08/2017 10:36 AM, JB via use-livecode wrote:
>>>
>>>> The file executes properly and the message is printed
>>>> showing I did not enter any arguments even though I
>>>> did try to and then it prints the file name and path like
>>>> I told it to from argv[0].
>>>>
>>>> JB
>>>
>>> In your original post you said "-args". The correct syntax is "--args"
>> (with two dashes rather than one), so if that's not a typo in your original
>> email, try correcting that and see what happens.
>>>
>>> --
>>> Mark Wieder
>>> [hidden email]
>>>
>>> _______________________________________________
>>> 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
>>
> _______________________________________________
> 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
|

Re: Shell argv

Bob Sneidar via use-livecode
If you are in terminal, and in the folder where your executable is, and you
type

./yourexecutablename arg1 arg2
does it do what you expect? (note the preceding dot . which means to start
at the working directory)

If the file is set to executable by you, it should work.  If you type the
command without the preceding dot slash ./ and if its not in the path, it
won't work, so you DO need to be explicit as to where it is. (hence the ./
it defines exactly where to find the file so being in the set PATH isn't
necessary)

If it DOES work that way from the command line, then in your script you can
a) set the folder to the location of the file, and then b) do a
shell("./theExe arg1 arg2") and it should work.  Or for a) you can give a
full path specification to the location of the file.

On Mon, May 8, 2017 at 12:54 PM, JB via use-livecode <
[hidden email]> wrote:

> Hi Mike,
>
> Thank you for the info.
>
> The dictionary for Shell states it needs to work
> from the Terminal to work correctly with Shell so
> I have been doing everything from the Terminal at
> this point.  I was trying to figure out how to write
> it properly in the Terminal so I could use similar
> code with the Shell.
>
> JB
>
>
> > On May 8, 2017, at 11:45 AM, Mike Bonner via use-livecode <
> [hidden email]> wrote:
> >
> > Seems to me, if its the compiled version, you shouldn't need to use
> "open"
> > at all.
> >
> > a simple
> > get shell("path/to/executable argument1 argument2")
> > If I understand what I read about "open" enough, it expects a file, that
> > will be opened in another app, like in Marks example.  (whatever.c opens
> > xcode)
> >
> > If you want to experiment with open, you could try the following..
> >
> > open -a /path/to/your/app /path/to/a/dummy/file/to/open --args arg1 arg2
> >
> > I'm guessing that if you can format this right, it'll report the name of
> > the dummy file, and arg1 and arg2 as you expect.
> >
> > But since you just want to pass arguments to your compiled program, I am
> > pretty sure you just need to use shell() and call it directly with the
> > arguments as part of the call.
> >
> >
> > On Mon, May 8, 2017 at 12:05 PM, JB via use-livecode <
> > [hidden email]> wrote:
> >
> >> That is a typo.
> >>
> >> In fact I tried every way and every
> >> place within the open script and if
> >> it is written different the code is not
> >> executed and I get and error.
> >>
> >> JB
> >>
> >>
> >>> On May 8, 2017, at 10:57 AM, Mark Wieder via use-livecode <
> >> [hidden email]> wrote:
> >>>
> >>> On 05/08/2017 10:36 AM, JB via use-livecode wrote:
> >>>
> >>>> The file executes properly and the message is printed
> >>>> showing I did not enter any arguments even though I
> >>>> did try to and then it prints the file name and path like
> >>>> I told it to from argv[0].
> >>>>
> >>>> JB
> >>>
> >>> In your original post you said "-args". The correct syntax is "--args"
> >> (with two dashes rather than one), so if that's not a typo in your
> original
> >> email, try correcting that and see what happens.
> >>>
> >>> --
> >>> Mark Wieder
> >>> [hidden email]
> >>>
> >>> _______________________________________________
> >>> 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
> >>
> > _______________________________________________
> > 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
>
_______________________________________________
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
|

Re: Shell argv

Bob Sneidar via use-livecode
I got it working with Glen’s code
but I needed to compile my code
from the terminal with gcc instead
of compiling it in Xcode.

I really appreciate your help and every-
ones help who replied.  It is all useful
information.

Thank you!
JB


> On May 8, 2017, at 1:32 PM, Mike Bonner via use-livecode <[hidden email]> wrote:
>
> If you are in terminal, and in the folder where your executable is, and you
> type
>
> /yourexecutablename arg1 arg2
> does it do what you expect? (note the preceding dot . which means to start
> at the working directory)
>
> If the file is set to executable by you, it should work.  If you type the
> command without the preceding dot slash ./ and if its not in the path, it
> won't work, so you DO need to be explicit as to where it is. (hence the ./
> it defines exactly where to find the file so being in the set PATH isn't
> necessary)
>
> If it DOES work that way from the command line, then in your script you can
> a) set the folder to the location of the file, and then b) do a
> shell("./theExe arg1 arg2") and it should work.  Or for a) you can give a
> full path specification to the location of the file.
>
> On Mon, May 8, 2017 at 12:54 PM, JB via use-livecode <
> [hidden email]> wrote:
>
>> Hi Mike,
>>
>> Thank you for the info.
>>
>> The dictionary for Shell states it needs to work
>> from the Terminal to work correctly with Shell so
>> I have been doing everything from the Terminal at
>> this point.  I was trying to figure out how to write
>> it properly in the Terminal so I could use similar
>> code with the Shell.
>>
>> JB
>>
>>
>>> On May 8, 2017, at 11:45 AM, Mike Bonner via use-livecode <
>> [hidden email]> wrote:
>>>
>>> Seems to me, if its the compiled version, you shouldn't need to use
>> "open"
>>> at all.
>>>
>>> a simple
>>> get shell("path/to/executable argument1 argument2")
>>> If I understand what I read about "open" enough, it expects a file, that
>>> will be opened in another app, like in Marks example.  (whatever.c opens
>>> xcode)
>>>
>>> If you want to experiment with open, you could try the following..
>>>
>>> open -a /path/to/your/app /path/to/a/dummy/file/to/open --args arg1 arg2
>>>
>>> I'm guessing that if you can format this right, it'll report the name of
>>> the dummy file, and arg1 and arg2 as you expect.
>>>
>>> But since you just want to pass arguments to your compiled program, I am
>>> pretty sure you just need to use shell() and call it directly with the
>>> arguments as part of the call.
>>>
>>>
>>> On Mon, May 8, 2017 at 12:05 PM, JB via use-livecode <
>>> [hidden email]> wrote:
>>>
>>>> That is a typo.
>>>>
>>>> In fact I tried every way and every
>>>> place within the open script and if
>>>> it is written different the code is not
>>>> executed and I get and error.
>>>>
>>>> JB
>>>>
>>>>
>>>>> On May 8, 2017, at 10:57 AM, Mark Wieder via use-livecode <
>>>> [hidden email]> wrote:
>>>>>
>>>>> On 05/08/2017 10:36 AM, JB via use-livecode wrote:
>>>>>
>>>>>> The file executes properly and the message is printed
>>>>>> showing I did not enter any arguments even though I
>>>>>> did try to and then it prints the file name and path like
>>>>>> I told it to from argv[0].
>>>>>>
>>>>>> JB
>>>>>
>>>>> In your original post you said "-args". The correct syntax is "--args"
>>>> (with two dashes rather than one), so if that's not a typo in your
>> original
>>>> email, try correcting that and see what happens.
>>>>>
>>>>> --
>>>>> Mark Wieder
>>>>> [hidden email]
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>
>>> _______________________________________________
>>> 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
>>
> _______________________________________________
> 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