none
launch an executable with parameters extracted from text file RRS feed

  • Question

  • If I have a text file that contains the the file name "sound.wav" as a string and I want to have powershell launch the executable sounder.exe with that extracted filename as its target or parameter, how do I structure that command? I need to be able to change the file name contained in the text file and have powershell play whatever file I call for using sounder.exe.
    Saturday, February 7, 2015 8:15 PM

Answers

  • Why is it so hard?

    $file=Get-Content relay.txt
    .\sounder.exe $file

    More than one:

    Get-Content relay.txt | %{.\sounder.exe $_ }


    ¯\_(ツ)_/¯

    • Marked as answer by Chalk-X CPG Sunday, February 8, 2015 10:05 PM
    Sunday, February 8, 2015 3:51 PM

All replies

  • HELP Start-Process --Full


    ¯\_(ツ)_/¯

    Saturday, February 7, 2015 8:24 PM
  • Can you give me a specific example based on my specific question?
    Sunday, February 8, 2015 2:22 PM
  • Can you post your script and any errors or a statement of what i snot happening?


    ¯\_(ツ)_/¯

    Sunday, February 8, 2015 2:32 PM
  • $wait = {

    do {
    $read = get-content relay.txt
    $request = $read
    } until ($read -notmatch '0')

    do {
    $read = get-content relay.txt
    } until ($read -match '1')

    &$play

    }

    $play = {

    if ($request -match 'apa_front') {.\sounder.exe apa_h_l.wav}
    if ($request -match 'apa_rear') {.\sounder.exe apa_h_r.wav}
    if ($request -match 'aspect_front') {.\sounder.exe aspect_h_l.wav}
    if ($request -match 'aspect_rear') {.\sounder.exe aspect_h_r.wav}
    if ($request -match 'curtain_both') {.\sounder.exe curtain_h.wav}
    if ($request -match 'curtain_front') {.\sounder.exe curtain_h_l.wav}
    if ($request -match 'curtain_rear') {.\sounder.exe curtain_h_r.wav}
    if ($request -match 'downarrow_front') {.\sounder.exe downarrow_h_l.wav}
    if ($request -match 'downarrow_rear') {.\sounder.exe downarrow_h_r.wav}
    if ($request -match 'dzoomminus_front') {.\sounder.exe dzoomminus_h_l.wav}
    if ($request -match 'dzoomminus_rear') {.\sounder.exe dzoomminus_h_r.wav}
    if ($request -match 'dzoomplus_front') {.\sounder.exe dzoomplus_h_l.wav}
    if ($request -match 'dzoomplus_rear') {.\sounder.exe dzoomplus_h_r.wav}
    if ($request -match 'enter_front') {.\sounder.exe enter_h_l.wav}
    if ($request -match 'enter_rear') {.\sounder.exe enter_h_r.wav}
    if ($request -match 'freeze_both') {.\sounder.exe freeze_h.wav}
    if ($request -match 'freeze_front') {.\sounder.exe freeze_h_l.wav}
    if ($request -match 'freeze_rear') {.\sounder.exe freeze_h_r.wav}
    if ($request -match 'keystone_front') {.\sounder.exe keystone_h_l.wav}
    if ($request -match 'keystone_rear') {.\sounder.exe keystone_h_r.wav}
    if ($request -match 'leftarrow_front') {.\sounder.exe leftarrow_h_l.wav}
    if ($request -match 'leftarrow_rear') {.\sounder.exe leftarrow_h_r.wav}
    if ($request -match 'menu_front') {.\sounder.exe menu_h_l.wav}
    if ($request -match 'menu_rear') {.\sounder.exe menu_h_r.wav}
    if ($request -match 'power_both') {.\sounder.exe power_h.wav}
    if ($request -match 'power_front') {.\sounder.exe power_h_l.wav}
    if ($request -match 'power_rear') {.\sounder.exe poweroff_h_r}
    if ($request -match 'reset_front') {.\sounder.exe reset_h_l.wav}
    if ($request -match 'reset_rear') {.\sounder.exe reset_h_r.wav}
    if ($request -match 'rightarrow_front') {.\sounder.exe rightarrow_h_l.wav}
    if ($request -match 'rightarrow_rear') {.\sounder.exe rightarrow_h_r.wav}
    if ($request -match 'source_both') {.\sounder.exe source_h.wav}
    if ($request -match 'source_front') {.\sounder.exe source_h_l.wav}
    if ($request -match 'source_rear') {.\sounder.exe source_h_r.wav}
    if ($request -match 'uparrow_front') {.\sounder.exe uparrow_h_l.wav}
    if ($request -match 'uparrow_rear') {.\sounder.exe uparrow_h_r.wav}

    Wait-Process sounder

    echo 0 > relay.txt

    &$wait

    }

    $read = get-content relay.txt

    &$wait

    The script works as is.  I'm trying to eliminate that long list of "if then"s. The desired media file name is contained in the variable $request. If I can insert it directly into the launch command, it will be more efficient.
    Sunday, February 8, 2015 2:44 PM
  • OOPS.  Let me amend my last statement.  The desired file name CAN be contained in the variable $request.  Currently I'm using descriptions instead of file names.  But I can easily amend that.
    Sunday, February 8, 2015 2:59 PM
  • Here's what it would look like with filenames in $request:

    $wait = {

    do {
    $read = get-content relay.txt
    $request = $read
    } until ($read -notmatch '0')

    do {
    $read = get-content relay.txt
    } until ($read -match '1')

    &$play

    }

    $play = {

    if ($request -match 'apa_h_l.wav') {.\sounder.exe apa_h_l.wav}
    if ($request -match 'apa_h_r.wav') {.\sounder.exe apa_h_r.wav} etc...etc...etc...

    Wait-Process sounder

    echo 0 > relay.txt

    &$wait

    }

    $read = get-content relay.txt

    &$wait

    Sunday, February 8, 2015 3:07 PM
  • Why is it so hard?

    $file=Get-Content relay.txt
    .\sounder.exe $file

    More than one:

    Get-Content relay.txt | %{.\sounder.exe $_ }


    ¯\_(ツ)_/¯

    • Marked as answer by Chalk-X CPG Sunday, February 8, 2015 10:05 PM
    Sunday, February 8, 2015 3:51 PM
  • Hmmm.  I'm pretty sure I tried this very obvious method yesterday.  Wonder what I did wrong.  Anyhow, I just tested this and it works fine.  I'll edit this into my script today.  Thanks.

    MUCH BETTER:

    $wait = {

    do {
    $read = get-content relay.txt
    $request = $read
    } until ($read -notmatch '0')

    do {
    $read = get-content relay.txt
    } until ($read -match '1')

    &$play

    }

    $play = {

    .\sounder.exe $request

    Wait-Process sounder

    echo 0 > relay.txt

    &$wait

    }

    $read = get-content relay.txt

    &$wait

    • Edited by Chalk-X CPG Sunday, February 8, 2015 10:24 PM
    Sunday, February 8, 2015 10:05 PM