GetFullCommandUsed returns the full command-line used to run the current process. It reconstructs the command from os.Args, adding quoting for arguments with spaces or quotes.
()
| 1681 | // GetFullCommandUsed returns the full command-line used to run the current process. |
| 1682 | // It reconstructs the command from os.Args, adding quoting for arguments with spaces or quotes. |
| 1683 | func GetFullCommandUsed() string { |
| 1684 | args := os.Args |
| 1685 | |
| 1686 | // Build the command string with proper quoting for arguments containing spaces |
| 1687 | var parts []string |
| 1688 | for _, arg := range args { |
| 1689 | if strings.Contains(arg, " ") || strings.Contains(arg, "\"") { |
| 1690 | // Quote the argument if it contains spaces or quotes |
| 1691 | parts = append(parts, fmt.Sprintf("%q", arg)) |
| 1692 | } else { |
| 1693 | parts = append(parts, arg) |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | cmdStr := strings.Join(parts, " ") |
| 1698 | |
| 1699 | return cmdStr |
| 1700 | } |