Shop OBEX P1 Docs P2 Docs Learn Events
system function call — Parallax Forums

system function call

Hello all.

First off, I'm not a developer. Now that I got that out of the way, below is my issue.

So I have a small C program that list directory contents. If I run that from the CMD, it works fine and does what it supposed to do.

C:\...>ListDirectoryExe
Volume in drive C has no label.
Volume Serial Number is E4A9-F680

Directory of ...

12/29/2019 12:13 PM <DIR> .
12/29/2019 12:13 PM <DIR> ..
12/29/2019 12:10 PM 38,912 ListDirectoryExe.exe
...
...
9 File(s) 1,465,670 bytes
3 Dir(s) 385,429,344,256 bytes free


Here's my code calling ListDirectoryExe:

#include "simpletools.h"
#include <stdlib.h>

int main()
{
system("ListDirectoryExe")
}


When I run Build, it fails on the following:

In function `_main':
(.text+0x6): undefined reference to `_system'

Am I using system() correctly or am I missing to declare or define something? Any help is appreciated.

Comments

  • AwesomeCronkAwesomeCronk Posts: 1,055
    edited 2019-12-29 21:05
    Is this for the Parallax Propeller (1 or 2)? Or for Windows? What are you trying to do?

    If you are running the c program from cmd, then Windows is executing it. If you are running it on the propeller, then the propeller cannot use system().
  • This is for Prop1 and the idea of the simple c program was to see if i can call external programs from within propeller. The result or output was not meant to be processed or redirected back into propeller for postprocessing. I was thinking that if system() was allowed, then I could fork it and keep the propeller running.

    I currently have two Prop Activiy Boards one with wifi which I programmed to help monitor and captured a ground mole; yes it works with the help of the wifi; when it got triggered, it sent me a http message to my iphone : )

    I'm done with the mole thing and I've another idea which brought me to system().

    I see that if system() was supported, it can be useful in so many ways; if something is triggered on Pin X, do system(myapp) for example.

    Any idea why system() not supported?
  • JonnyMacJonnyMac Posts: 9,102
    edited 2019-12-29 22:59
    I'm not a big C guy, but system() suggests that you are directing commands to an operating system (e.g., Linux or Windows). The Propeller is running a program that is NOT running in an operating system; it's running on the bare metal. If you want the Propeller to command your PC to do something, you'll need to have the Propeller send a serial message to the PC that is running a message processor application. The message processor (an app on your PC) could call other programs using the system() mechanism.
  • It should be fairly easy to write a system() function. It just needs to read a Prop binary file into memory and then perform a cogstart. However, programs written in C normally start from hub RAM location zero, so the original program in hub RAM that calls the system() function will be overwritten.

    Things become more complicated if you want to have multiple programs running at the same time. The Spinix OS does this by running programs written in Spin, which can be easily relocated in RAM.
  • Thanks for the input guys. What I had in mind is probably more difficult to implement than I originally thought after reading your comments. I was hoping to use the same COM port for the data com between the OS and propeller but that presents a challenge in itself and as JonnyMac pointed, out a "listener" on the running OS maybe required to actually execute a command when it's triggered.

    Will have to think about this more and see if there's another way to do it.

    Thanks everyone for your valuable input...always appreciated.

    jav
  • Do you have experience with Python? There is a serial library for it, and I know for a fact that it can execute other apps (with arguments). No compiler required. Runs on any OS.

    I once wrote a tiny Python script for a TV commercial to demonstrate the speed of SSD over a spinning drive. When the PC booted it ran the script that sent a serial message to a Propeller board which changed the color of a light and then unlocked a box using a servo. Inside the box was a paintball gun. Needless to say, the person with the fastest PC (SSD) got to their paintball gun first and could shoot the daylights out of the other guy.
  • I used Python scripting more than 5years ago to automate systems audit and simplify evidence gathering and it ran on three different *nixes without any problem. I've not used python anymore since then so it's safe to say the skills is well rotted away : )

    I like your demo though and I take it you got to your paintball gun first : ) My process would be the opposite; the prop board would send a signal to the running OS(through some method, serial or otherwise), windows or *nix, and then it takes off from there.

    I'm looking at the three Python Cookbooks on my shelf and I'm almost afraid to touch them hehee
Sign In or Register to comment.