Kamil Kamil - 6 months ago 43
Swift Question

Swift - compile program with input parameters

I have the following program in Swift (


print("Enter x: ");
var x = readLine()!
print("x is " + x)

print("Enter y: ");
var y = readLine()!
print("y is " + y)

And I have an input file that contains the following (


Usually, I compile using
swift myscript.swift
. However, I want to compile by passing the input file so that I am not prompted for input at the terminal. Is there a way to achieve this?


I found the solution. The command to compile is as follows:

swift myscript.swift < input.txt

There is no need for additional swift code.