0

In Windows 10 with PowerShell 7.3.3. I have a program foo.exe on my path. I can invoke it like this:

foo test 

I want to insert the parameter --bar before all arguments. My first thought is to create a function in my $PROFILE like this:

function foo { foo --bar @args } 

Obviously that doesn't work, because it results in an endless loop (the function calls itself).

How can I invoke the command/program foo from within the function foo? I'm guessing I can research and do something like the Bash $(pwd) and then create a path to the original executable, and hopefully that would bypass the function. But is there an easier way?

8
  • You could call the file with extension bat calling an exe. Also see following : stackoverflow.com/questions/14311606/… Commented Mar 16, 2023 at 17:21
  • Just call the program by name including extension and use $ or @ in place of %. Try this: function foo { foo.exe --bar @args }. Commented Mar 16, 2023 at 17:53
  • Thanks. I had thought of the foo.exe trick when I stepped away. If one of you wants to write that up in an official answer, I'll accept it. Otherwise I'll write up an answer myself. Commented Mar 16, 2023 at 19:54
  • This is a pretty generic question, so there is propably already an existing Q&A. Commented Mar 16, 2023 at 22:05
  • Unfortunately my question was a little too generic, because what I was really wanting to do was to pass --% instead of --bar, which doesn't work. ☹ See comments to stackoverflow.com/a/73650127 . Commented Mar 16, 2023 at 22:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.