How to pass command line args to startx?

So i have an old computer that i want to use to watch tv. The plan was install freebsd, load up hard drive with content, plug in the hdmi, and simply pass command line args to startx to select the file i want to watch ie
startx vlc path/to/file
i tried just adding
exec $1 $2 $3 $4
and also
exec xterm -e $1 $2 $3 $4
to the system wide xinitrc (single user setup cuz its just a tv box) but this just crashes the x server. i can run vlc from xterm but then i gotta fuck around with a mouse to change focus. for simplicity and viewing comfort i dont wanna have to fuck with a mouse.
 
try startx /path/to/vlc /path/to/file

I've found startx to be flaky about path to executable if it is missing.

Starting the X server and clients can be kind of tricky if you want to do custom stuff. You need to indirectly start the X server in the background, then execute at least one client, and if all clients exit then the X server itself will exit. In the past i've done stuff like

(X {x-options} &; sleep 2; client1&; client2 &; client3)
 
What is the error you get when X crashes?

For me, $1 in .xinitrc is not the first parameter passed to startx, it's "xterm", for some reason, and my first argument comes as $2 (this is a very fresh install). Beside the path resolution problems mentioned by kent_dorfman766, you can try passing values through env variables, if you don't mind them being then exposed to all programs then started by X:

Code:
$ cat ~/.xinitrc
exec xterm -e "$MY_COMMAND"

$ MY_COMMAND="/usr/local/bin/vlc /home/user/Video/whatever.mp4" startx
 
the more easy way is the .xinitrc file
remember that you have to put the commands in the background until the last one,and when close the last one,Xorg exit
example
~/.xinitrc

Code:
vlc &
xterm

but you run a window manager?
 
You either add lines in your ~/.xinitrc, as the others said, or do it in your WM's config file, like I start VLC automatically in my fvwm at the start ~/.fvwm/fvwm.config:
Code:
[...]
# Start Function
DestroyFunc StartFunction
AddToFunc   StartFunction
[...]
+ I Test (Init) Exec exec vlc /path/to/myplayist.xspf
+ I GotoDesk 0
[...]
 
beastiegirl for example, I use openbox at times. There is a file $HOME/.config/openbox where it has its configuration, including an autostart file. I just want it to start with a background and tint2 (a window manager bar). So, my $HOME/.config/openbox/autostart reads

feh --bg-scale backgrounds/mybackground.jpg & (sleep 3 && tint2) & (sleep 3 && xbiff) &

That's adding extra stuff as examples, I don't use xbiff very often these days, just trying to show starting multiple things.

I think the first question we have might be, What window manager or desktop environment are you using when you startx?
 
try startx /path/to/vlc /path/to/file

I've found startx to be flaky about path to executable if it is missing.

Starting the X server and clients can be kind of tricky if you want to do custom stuff. You need to indirectly start the X server in the background, then execute at least one client, and if all clients exit then the X server itself will exit. In the past i've done stuff like

(X {x-options} &; sleep 2; client1&; client2 &; client3)
already tried startx /path/to/vlc /path/to/file
 
What is the error you get when X crashes?

For me, $1 in .xinitrc is not the first parameter passed to startx, it's "xterm", for some reason, and my first argument comes as $2 (this is a very fresh install). Beside the path resolution problems mentioned by kent_dorfman766, you can try passing values through env variables, if you don't mind them being then exposed to all programs then started by X:

Code:
$ cat ~/.xinitrc
exec xterm -e "$MY_COMMAND"

$ MY_COMMAND="/usr/local/bin/vlc /home/user/Video/whatever.mp4" startx
it doesnt have any error it just kinda dies. when i add echo $1 $2 $3 $4 it doesnt acutally echo anything. dont want to use environment vars as it feels like it would be too much of a pain when im just trying to watch tv.
 
beastiegirl for example, I use openbox at times. There is a file $HOME/.config/openbox where it has its configuration, including an autostart file. I just want it to start with a background and tint2 (a window manager bar). So, my $HOME/.config/openbox/autostart reads


feh --bg-scale backgrounds/mybackground.jpg &
(sleep 3 && tint2) &
(sleep 3 && xbiff) &


That's adding extra stuff as examples, I don't use xbiff very often these days, just trying to show starting multiple things.

I think the first question we have might be, What window manager or desktop environment are you using when you startx?
yeah i know how to run additional programs. the part i am having problems with is passing args to them. i want to just type startx /path/to/file and pass /path/to/file to vlc
 
What I did in my test that helped me figure the first argument was "xterm" was to redirect it in a file:

Code:
echo $1 $2 $3 $4 > ~/foo

You can then inspect it.
i redirected it to a file and it created an empty file. looks like none of the arguments get passed to it.
 
the more easy way is the .xinitrc file
remember that you have to put the commands in the background until the last one,and when close the last one,Xorg exit
example
~/.xinitrc

Code:
vlc &
xterm

but you run a window manager?
Doing this for years. Thought it was the normal way. 😁
The window manager (openbox) is the last program called in ~/.xinitrc and it's not backgrounded like everything interactive before it. For in case the window manager crashes for some reason, I added sleep 9999999 after it, so X keeps running but you have to restart the desktop programs. If the script really ends you go back to system console and all X programs get terminated.
 
[…] and simply pass command line args to startx to select the file i want to watch ie […]
I have no issue if I specify an absolute pathname like kent_dorfman766 suggested. Instead of editing ~/.xinitrc you can always take two separate steps:​
  1. startx(1)
    Bash:
    startx -- :0 # -- :0 can be omitted if there’s only one X
  2. From another vt(4) console start vlc(1) with the DISPLAY environment variable set accordingly.​
    Bash:
    DISPLAY=:0 cvlc /tmp/ts.m3u --play-and-exit
 
i redirected it to a file and it created an empty file. looks like none of the arguments get passed to it.
well, that's a problem, since you're trying to use those params in you exec line. :) It means they are not defined.

You said you were putting that stuff in system wide xinitrc, maybe try putting it in ~/.xinitrc instead. That's where I was using them, personally, and I can confirm params are passed correctly with that one, on my system.

Also, I second SirDice request, please show us the log, I have hard time believing there is no error at all. Although… maybe it makes sense, actually. Because:

Code:
$ exec
$ echo $?
0

If you script is calling exec $1 $2 $3 $4 and those variables are empty, then it's just an empty exec, that happily returns successfully immediately.
 
I have no issue if I specify an absolute pathname like kent_dorfman766 suggested. Instead of editing ~/.xinitrc you can always take two separate steps:​
  1. startx(1)
    Bash:
    startx -- :0 # -- :0 can be omitted if there’s only one X
  2. From another vt(4) console start vlc(1) with the DISPLAY environment variable set accordingly.​
    Bash:
    DISPLAY=:0 cvlc /tmp/ts.m3u --play-and-exit
thats also gonna be too much of a pain in the ass when i just want to watch tv
 
error message calls it a directory lol
The error message would be "no such file or directory". If you get "not a directory" you tried to cd to it. And it means it does exist as a file, or else you'd get a similar "no such file or directory".

Code:
dice@williscorto:~ % cd /var/log/Xorg.0.log
/var/log/Xorg.0.log: Not a directory.
dice@williscorto:~ % ls -l /var/log/Xorg.0.log
-rw-r--r--  1 root wheel 24372 Jan  5 15:59 /var/log/Xorg.0.log
Code:
dice@maelcum:~ % cat /var/log/Xorg.0.log
cat: /var/log/Xorg.0.log: No such file or directory
dice@maelcum:~ % cd /var/log/Xorg.0.log
/var/log/Xorg.0.log: No such file or directory.
dice@maelcum:~ % ls -l /var/log/Xorg.0.log
ls: /var/log/Xorg.0.log: No such file or directory
 
Back
Top