1

I have the following program in Swift (myscript.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 (input.txt):

4
6

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?

Kamil
  • 968
  • 1
  • 8
  • 18

1 Answers1

0

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

swift myscript.swift < input.txt

There is no need for additional swift code.

Kamil
  • 968
  • 1
  • 8
  • 18