#parseOSCommand extension to string

17 views
Skip to first unread message

Louis LaBrunda

unread,
Jul 22, 2024, 10:47:34 AM (3 days ago) Jul 22
to VAST Community Forum
I hope everyone is enjoying summer!  Although it might be winder for Mariano,

I have been trying various ways to play sounds (wav files, etc...) on Linux and Windows.  Originally I was running a program like aplay and VLC on Linux and VLC and WMP on Windows.  I tried using platform functions.  I can do that on Windows but couldn't on Linux (I'll rant about that in a minute).  So, I'm back to using #OsProcessStarter to call a program to play the sound.

#OsProcessStarter works great but it wants the command and the args in an ordered collection.  That generally isn't a big deal but I want the user to be able to choose the program to be used to play the sound file (see the rant).  That would require my settings code to have the user enter the entries of the collection that #OsProcessStarter needs.  That is doable but a mess.  I much prefer the user enter a string for the sound playing program with %1 as a place holder for the path to the file (different sounds can be played at different times).  This is easy enough to do but then I have to break that string apart to feed #OsProcessStarter the collection it wants.

I wrote an extension to #EsString to parse the string and answer an #OrderedCollection that #OsProcessStarter is happy with (see attached).  Feel free to use it.  Instantiations can add it to the product if they like.  They may also think about adding a method to #OsProcessStarter that accepts the command as a string, and then parses it into the command collection it needs.

Now for the rant.  In this case Widows is innocent, it has both commands and platform functions that can be called to play sound files.  Linux also has commands and platform functions but they no-longer if called by a super user (sudo).  I have a patched/hacked VLC that works but I'm not crazy about using patched code that can get unpatched with any update.  The authors of the sound/audio systems have their reasons for not allowing super users to call the sound system code and they are probably good reasons.  BUT, if one has super user powers, one can mess things up without involving the sound system.  Sure, if you want to warn people off, warn them off but give us a way to take the risk and do what we want.  Yea, I know I could get and modify the source and compile it, bla bla bla.  No thanks.

Lou

parseOSCommand.st

Mariano Martinez Peck

unread,
Jul 22, 2024, 12:09:20 PM (3 days ago) Jul 22
to VA Smalltalk
Hi Louis,

The rationale for the array’s arguments is because it’s best practice to avoid well known command line injection attacks. In addition to that, we have quoting and escaping sanitization down in the vm when it parses it.

That being said, if you still want to pass String with simple split rules (which then String array is created from), you can do the following. Examples:

OsProcessStarter startShell: 'wmic cpu get loadpercentage'

OsProcessStarter startShell: 'cat /etc/os-release'

Hope this helps,





--
You received this message because you are subscribed to the Google Groups "VAST Community Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to va-smalltalk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/8ad7b8ab-d4e9-4822-bb5a-c9d280eb0aban%40googlegroups.com.


--

Mariano Martinez Peck

VAST Team Lead

Senior Software Engineer

 mp...@instantiations.com
 @MartinezPeck
 /mariano-martinez-peck
 instantiations.com
TwitterLinkedInVAST Community ForumGitHubYouTubepub.dev
Reply all
Reply to author
Forward
0 new messages