[SOLVED] "qm guest exec" problem

Linyu

Well-Known Member
Jun 14, 2019
43
2
48
25
Hi, I am a beginner, and I have a Windows 2012R2 VM with guest agent installation. And I am now trying to use qm guest exec VMID to run a program I have put in the Disk C: of the VM, Which is "C:\\program.exe", this program have 4 args I need to pass in, I've tried many types and I can't run it, can you give me an example?I can't get the answer from google..

Code:
root@node-us:~# qm guest exec 101 "start C:\\program.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
root@node-us:~# qm guest exec 101 "C:\\program.exe" "arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
...

So, can you give me an example to do this well? Thank you very much~
 
Try first to remove the double "\".

QM Agent is installed and activated? You see some Information about the IPs in PVE GUI?
 
Thank you, and yes, I can see the IPs in PVE GUI,
I got this:
Code:
node-us:~# qm guest exec 101 "start C:program.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (No such file or directory)'

But I am pretty sure it's there with that name :p
 
Please use an correct Windows Path, its like
Code:
C:\program.exe
and not
Code:
C:\\program.exe
or
Code:
C:program.exe
or
Code:
C:/program.exe
.
 
:(Look:
Code:
root@node-us:~# qm guest exec 101 "start C:\initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
root@node-us:~# qm guest exec 101 "start C:/initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
root@node-us:~# qm guest exec 101 "C:/initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (No such file or directory)'
root@node-us:~# qm guest exec 101 "C://initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (No such file or directory)'
root@node-us:~# qm guest exec 101 "C:\initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
root@node-us:~# qm guest exec 101 "start C:\initer.exe arg1 arg2 arg3 arg4"
Agent error: Guest agent command failed, error was 'Failed to execute child process (Invalid argument)'
 
Okay, problem solved, this will work:

Code:
qm guest exec 101 "C:/program.exe" "arg1" "arg2" "arg3" "arg4"
 
I have kinda similar kind of problem. I did get this to work now if I see the referenced "separate all arguments" approach. But I still have problem with dash.

This works:
Code:
root@phoenix:~# qm guest exec 1015 "df"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "Filesystem     1K-blocks    Used Available Use% Mounted on\nudev              490548       0    490548   0% /dev\ntmpfs             101072    7948     93124   8% /run\n/dev/sda1        5092992 1406012   3408556  30% /\ntmpfs             505352       0    505352   0% /dev/shm\ntmpfs               5120       0      5120   0% /run/lock\ntmpfs             505352       0    505352   0% /sys/fs/cgroup\n"
}

This works:
Code:
root@phoenix:~# qm guest exec 1015 "df" "/"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "Filesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda1        5092992 1406012   3408556  30% /\n"
}

This does not. It seems that qm command thinks that it's an [OPTION] for him and not to be sent to qemu agent.
Code:
root@phoenix:~# qm guest exec 1015 "df" "-h"
Unknown option: h
400 unable to parse option
qm guest exec <vmid> [<extra-args>] [OPTIONS]
 
After the command you need "--" to tell the qm command to ignore further options:

Code:
# qm guest exec 104 /usr/sbin/fstrim -- "-av"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "/boot: 771.8 MiB (809226240 bytes) trimmed\n/: 26.4 GiB (28355977216 bytes) trimmed\n"
}
 
Haha , cool. This was exactly the problem - I wanted to send mass trim to all my guests and "trim -av" failed. I just used "df" example since it's more reproducible. Thanks.
 
  • Like
Reactions: Linyu
Yep, I do this just before snapshots:

Code:
for VM in $(qm list | sed '1d' | awk '{print $1}')
do
/usr/sbin/qm guest exec $VM /usr/sbin/fstrim -- "-a"
/usr/bin/vzdump $VM --mode snapshot --mailnotification always --mailto your@email
done
 
  • Like
Reactions: Linyu