Jump to content
UBot Underground

The Shell command


Recommended Posts

The Shell command works fine for me if i am executing a Batch file or command line type of program.

 

But is there a way to pass a parameter to the program/batch file being executed. I have tried several ways but to no avail.

 

Thanks!

 

Buddy

ubot-008.JPG

Link to post
Share on other sites

The Shell command works fine for me if i am executing a Batch file or command line type of program.

 

But is there a way to pass a parameter to the program/batch file being executed. I have tried several ways but to no avail.

 

Thanks!

 

Buddy

 

Just chiming in that I'm interested in knowing if you can pass variables as well.

Link to post
Share on other sites

Sorry I should have been more clear.

 

No, I mean a parameter to a Batch file. Like:

 

process-this.cmd myvariable

 

Inside the batch file there would be a command like

 

del %1.dat

 

or

 

copy %1.dat %.bak

 

The %1 would be the myvariable being passed.

 

In most Shelling environments this is possible. Having this capability allows the user to build more generic batch files that can be used in varying capacities. But then you know that already. hehehe

 

Buddy

Link to post
Share on other sites

After more testing and more deadends I am becoming more convinced that this needs to be expanded.

 

Since uBot does not have a library of File Management function (if someone has them PLEASE share) then maybe its time some should be created.

 

Here is what I have been trying to do.

 

I hate having to hard code anything because I think flexibility is lost. So when I Shell to a batch file it is usually when I am trying to backup a file before re-writing to it. So if I Shell to a batch file called "rename.cmd". Then I would like to pass a parameter from a UI Text Box like a filename. So in essence my Shell command would look like

 

Shell > rename.cmd {1}

 

Where {1} would be my UI Text Box parameter.

 

As it stands right now. It does not work.

 

IF I am in a command window and I execute "rename.cmd somename" it will take the "somename" and allow me to use it within my batch file as a variable called %1.

 

So if anyone has any ideas as how to accomplish this then I would be greatful.

 

Buddy

Link to post
Share on other sites

After more testing and more deadends I am becoming more convinced that this needs to be expanded.

 

Since uBot does not have a library of File Management function (if someone has them PLEASE share) then maybe its time some should be created.

 

Here is what I have been trying to do.

 

I hate having to hard code anything because I think flexibility is lost. So when I Shell to a batch file it is usually when I am trying to backup a file before re-writing to it. So if I Shell to a batch file called "rename.cmd". Then I would like to pass a parameter from a UI Text Box like a filename. So in essence my Shell command would look like

 

Shell > rename.cmd {1}

 

Where {1} would be my UI Text Box parameter.

 

As it stands right now. It does not work.

 

IF I am in a command window and I execute "rename.cmd somename" it will take the "somename" and allow me to use it within my batch file as a variable called %1.

 

So if anyone has any ideas as how to accomplish this then I would be greatful.

 

Buddy

 

Could you write the batch file from within ubot with the commands and parameters in it and then use shell to execute the just written file? So basically you write out a file called temp.cmd which contains the commands "ren old.txt whatever.txt" and then "shell temp.cmd"

 

Andy

Link to post
Share on other sites

@alcr - No batch files cannot read from text files. Batch files take their input from the command line. This is a hang over from the DOS days.

 

@Andy - Interesting. I will have to think about that. Shooting from the hip I would think that would add overhead (in terms of code size) to the overall program being developed.

 

Maybe this would be for some projects but when File Management functions are needed then I still favor a path that can be used within uBot.

 

For instance,

 

$create folder

$remove folder

$rename file

$delete file

 

Aftr all, we have $document folder. We need more.

 

Buddy

Link to post
Share on other sites

The_Brit,

 

Thanks for the code! I never considered that kind of a layout. I tried it out but it did not work for me. The error I am getting is attached. Rather than running a delete as in your example batch file. I just setup a command like this "dir %1.* > testdirlisting.txt"

 

I tested my batch file from a an actual shell window to ensure that it worked without errors and it did. I then ran it like you setup using your exact code and it failed.

 

Buddy

ubot-011.JPG

Link to post
Share on other sites

The_Brit,

 

Thanks for the code! I never considered that kind of a layout. I tried it out but it did not work for me. The error I am getting is attached. Rather than running a delete as in your example batch file. I just setup a command like this "dir %1.* > testdirlisting.txt"

 

I tested my batch file from a an actual shell window to ensure that it worked without errors and it did. I then ran it like you setup using your exact code and it failed.

 

Buddy

I'm not sure why you are getting that error, maybe somebody else can shed some light on it. I'll see if I can alter mine to run the commands you want to use.

Link to post
Share on other sites

If it is working for you then that is great. Which makes me think that this is the right path towards resolving the issue.

 

Buddy

Link to post
Share on other sites

A VERY INTERESTING discovery!

 

It works flawlessly when compiled but not in the UBot environment.

 

Is this by design or ?

 

Maybe the Masters will look at it.

 

Thanks for your help on this The-Brit!

 

Buddy

Link to post
Share on other sites

A VERY INTERESTING discovery!

 

It works flawlessly when compiled but not in the UBot environment.

 

Is this by design or ?

 

Maybe the Masters will look at it.

 

Thanks for your help on this The-Brit!

 

Buddy

Happy to have been able to contribute after only having the product for about a week.

 

Dave

Link to post
Share on other sites
  • 2 years later...

A VERY INTERESTING discovery!

 

It works flawlessly when compiled but not in the UBot environment.

 

Is this by design or ?

 

Maybe the Masters will look at it.

 

Thanks for your help on this The-Brit!

 

Buddy

 

This was very useful to know... been wondering the last hour why on Earth it woudlnt Shell and execute.

 

Compliling makes it work... Thanks for the discovery

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...