How to create & work with temporary file

A program has multiple facets / sub-programs but it has no system to integrate those together; so it’s up to the user to make multiple commands when desiring to do a task with more than 1 sub-program. I could create files then delete them, but I’m wondering if there’s a way to create a script which those separate task could be put into a temporary file and link those sub-programs through those temporary files. For example:

create temporary file T1, T2;
[1st command] $T1;
echo "1st command size: ", filesize ($T1);
[2nd command part 1] $T2 [2nd command part 2];
echo "2nd command size: ", filesize ($T2);
[3rd command part 1] $T1 [3rd command part 2] $T2 [3rd command part 3] output.ext;

In the above the only regular file created is output.ext.

Thank you kindly for your help

DynV,
Welcome to the forum. :wave:t4:

To create a temporary file you can use

Please read the help topic completely including the examples to learn how to use it.

But what exactly do you mean with

?

There’s an example in the OP.

… an example of what? How can we help you? Could you elaborate a little more detailed? Did you read the help? Did it help you already?

Do you see the blockquote in the OP? I never created a powershell script before, I need to figure out how to do commands, as in Windows command prompt, with it before I can use the temporary file.

So you may start with learning the very basics of PowerShell first. :wink: It is beyond the scope of a forum like this to teach you how to write scripts.

I’d recommend to start with good book or an online tutorial or even some youtube videos would be useful to get you started.

I think I’ll be able to using Batch convert videos using ffmpeg and powershell · GitHub as an example. However, I I run “ffmpeg --version” in a command prompt it will give me an earlier version than I recently downloaded. How can I set the path of ffmpeg in the example? Something like ffmpeg.setpath([path]).

This is a PowerShell forum. I don’t know nothing about ffmpeg. But from a scripting point of view I’d recommend to use the full path instead if you want to use a particular version. :wink:

I’m trying to create the script step-by-step and thought the simplest one would be

$fullPathFfmpeg = “C:\Users\Public\Libraries\programs\ffmpeg-5.1-essentials_build\bin\ffmpeg.exe”

$fileInput1 = “PATH_BEGINNING\Downloads\African senegal parrot talking-T9XC-csQA0o.mp4”
$fileInput2 = “PATH_BEGINNING\Downloads\Alex African Grey Parrot talking to a Persian cat-0nIezlem7aw.mp4”
$fileOutput = “PATH_BEGINNING\Videos\African_senegal_parrot_talking-Alex_African_Grey_Parrot_talking_to_a_Persian_cat.mp4”

$fullPathFfmpeg -f concat -i “concat:$fileInput1|$fileInput2” -c copy $fileOutput

in a text file which I’m trying to run in the following

PS PATH_BEGINNING\Documents> .\African_senegal_parrot_talking-Alex_African_Grey_Parrot_talking_to_a_Persian_cat.ps1

that yielded

At PATH_BEGINNING\African_senegal_parrot_talking-Alex_African_Grey_Parrot_talking_to_a_Persian_cat.p
s1:7 char:19

  • $fullPathFfmpeg -f concat -i “concat:$fileInput1|$fileInput2” -c copy …
  •               ~
    

You must provide a value expression following the ‘-f’ operator.
At PATH_BEGINNING\Documents\African_senegal_parrot_talking-Alex_African_Grey_Parrot_talking_to_a_Persian_cat.p
s1:7 char:20

  • $fullPathFfmpeg -f concat -i “concat:$fileInput1|$fileInput2” -c copy …
  •                ~~~~~~
    

Unexpected token ‘concat’ in expression or statement.
+ CategoryInfo : ParserError: (:slight_smile: , ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression

What am I doing wrong?

  • 1
    When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Do not use the blockquote format! :point_up_2:t4:

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

  • 2
    Learn the basics of PowerShell. That includes how to read and understand error messages! :wink:

  • 3
    As you can read in the error message -f is a PowerShell operator. When you run an external tool using the same name as a command line argument you have to tell PowerShell not to parse it as PowerShell operator. You could use the stop parsing operator (--%). But you have to make sure you place it after all other things you want PowerShell to parse. :point_up_2:t4:
    I don’t know if that works but you could try this:

$fullPathFfmpeg -i "concat:$fileInput1|$fileInput2" -c copy $fileOutput --% -f concat 

You may have to escape the pipe symbol as well.

  • 4
    Another option would be to use the Start-Process cmdlet
Start-Process -FilePath $fullPathFfmpeg -ArgumentList "-f concat -i 'concat:$fileInput1|$fileInput2' -c copy $fileOutput"

Again … you may have to escape the pipe symbol.

Please always read the help for the cmdlets you’re about to use completely including the examples.

At the moment you actually not using any PowerShell functionality. If it’s easier for you you may keep using batch/cmd files instead of PowerShell scripts.

WHAT TEXT FILE??? Are you talking about a script? :thinking: A text file cannot run nothing because it’s just text.